Initial commit.
This commit is contained in:
21
k8s/.terraform.lock.hcl
generated
Normal file
21
k8s/.terraform.lock.hcl
generated
Normal file
@ -0,0 +1,21 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/kubernetes" {
|
||||
version = "2.8.0"
|
||||
constraints = ">= 2.0.0"
|
||||
hashes = [
|
||||
"h1:UZCCMTH49ziz6YDV5oCCoOHypOxZWvzc59IfZxVdWeI=",
|
||||
"zh:0cf42c17c05ae5f0f5eb4b2c375dd2068960b97392e50823e47b2cee7b5e01be",
|
||||
"zh:29e3751eceae92c7400a17fe3a5394ed761627bcadfda66e7ac91d6485c37927",
|
||||
"zh:2d95584504c651e1e2e49fbb5fae1736e32a505102c3dbd2c319b26884a7d3d5",
|
||||
"zh:4a5f1d915c19e7c7b4f04d7d68f82db2c872dad75b9e6f33a6ddce43aa160405",
|
||||
"zh:4b959187fd2c884a4c6606e1c4edc7b506ec4cadb2742831f37aca1463eb349d",
|
||||
"zh:5e76a2b81c93d9904d50c2a703845f79d2b080c2f87c07ef8f168592033d638f",
|
||||
"zh:c5aa21a7168f96afa4b4776cbd7eefd3e1f47d48430dce75c7f761f2d2fac77b",
|
||||
"zh:d45e8bd98fc6752ea087e744efdafb209e7ec5a4224f9affee0a24fb51d26bb9",
|
||||
"zh:d4739255076ed7f3ac2a06aef89e8e48a87667f3e470c514ce2185c0569cc1fb",
|
||||
"zh:dbd2f11529a422ffd17040a70c0cc2802b7f1be2499e976dc22f1138d022b1b4",
|
||||
"zh:dbd5357082b2485bb9978bce5b6d508d6b431d15c53bfa1fcc2781131826b5d8",
|
||||
]
|
||||
}
|
12
k8s/k8s.tf
Normal file
12
k8s/k8s.tf
Normal file
@ -0,0 +1,12 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = ">= 2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
config_path = "~/.kube/config"
|
||||
}
|
78
k8s/nginx.tf
Normal file
78
k8s/nginx.tf
Normal file
@ -0,0 +1,78 @@
|
||||
resource "kubernetes_namespace" "testaroo" {
|
||||
metadata {
|
||||
name = "testaroo"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "basic-pod" {
|
||||
metadata {
|
||||
name = "alpine"
|
||||
namespace = kubernetes_namespace.testaroo.metadata.0.name
|
||||
}
|
||||
|
||||
spec {
|
||||
container {
|
||||
name = "alpine"
|
||||
image = "alpine:3.15"
|
||||
command = ["sh", "-c", "while true; do sleep 3600; done"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "testaroo" {
|
||||
count = var.enable_nginx
|
||||
|
||||
metadata {
|
||||
name = "nginx"
|
||||
namespace = kubernetes_namespace.testaroo.metadata.0.name
|
||||
}
|
||||
|
||||
spec {
|
||||
replicas = 2
|
||||
selector {
|
||||
match_labels = {
|
||||
app = "Nginx"
|
||||
}
|
||||
}
|
||||
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
app = "Nginx"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
container {
|
||||
image = "nginx"
|
||||
name = "nginx-container"
|
||||
port {
|
||||
container_port = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "testaroo" {
|
||||
count = var.enable_nginx
|
||||
|
||||
metadata {
|
||||
name = "nginx"
|
||||
namespace = kubernetes_namespace.testaroo.metadata.0.name
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
app = kubernetes_deployment.testaroo[0].spec.0.template.0.metadata.0.labels.app
|
||||
}
|
||||
|
||||
type = "NodePort"
|
||||
port {
|
||||
node_port = 31234
|
||||
port = 80
|
||||
target_port = 80
|
||||
}
|
||||
}
|
||||
}
|
10
k8s/samples/basic.yaml
Normal file
10
k8s/samples/basic.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: alpine
|
||||
spec:
|
||||
containers:
|
||||
- name: alpine
|
||||
image: alpine:3.15
|
||||
command: ["sh", "-c", "while true; do sleep 3600; done"]
|
26
k8s/samples/nginx.yaml
Normal file
26
k8s/samples/nginx.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
# A nginx instance with a NodePort.
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: nginx
|
||||
labels:
|
||||
app: nginx
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.21
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
ports:
|
||||
- port: 8123 # Port exposed in cluster
|
||||
targetPort: 80 # Port inside container
|
||||
protocol: TCP
|
||||
nodePort: 31234
|
||||
selector:
|
||||
app: nginx
|
||||
type: NodePort
|
4
k8s/variables.tf
Normal file
4
k8s/variables.tf
Normal file
@ -0,0 +1,4 @@
|
||||
variable "enable_nginx" {
|
||||
type = number
|
||||
default = 0
|
||||
}
|
Reference in New Issue
Block a user