This repository has been archived on 2022-02-19. You can view files and clone it, but cannot push or open issues or pull requests.
infra-aws-eks/k8s/nginx.tf

100 lines
1.7 KiB
Terraform
Raw Normal View History

2022-02-11 14:42:37 +01:00
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 {
2022-02-12 10:02:17 +01:00
name = "nginx-np"
2022-02-11 14:42:37 +01:00
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
}
}
}
2022-02-12 10:02:17 +01:00
resource "kubernetes_service" "testaroo-lb" {
count = var.enable_nginx
metadata {
name = "nginx-lb"
namespace = kubernetes_namespace.testaroo.metadata.0.name
}
spec {
selector = {
app = kubernetes_deployment.testaroo[0].spec.0.template.0.metadata.0.labels.app
}
type = "LoadBalancer"
port {
port = 80
target_port = 80
}
}
}