79 lines
1.3 KiB
HCL
79 lines
1.3 KiB
HCL
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
|
|
}
|
|
}
|
|
}
|