From 4326717c1989bbfc38a1ea7f7539bde56d0e3d11 Mon Sep 17 00:00:00 2001 From: x p k Date: Tue, 28 Jul 2020 17:02:15 +0800 Subject: [PATCH] NEW: terraform and kubernetes --- tf-modulised/kubernetes/sshd/nginx-deploy.tf | 66 ++++++++++++++++++++ tf-modulised/kubernetes/sshd/nginx-pod.tf | 20 ------ 2 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 tf-modulised/kubernetes/sshd/nginx-deploy.tf delete mode 100644 tf-modulised/kubernetes/sshd/nginx-pod.tf diff --git a/tf-modulised/kubernetes/sshd/nginx-deploy.tf b/tf-modulised/kubernetes/sshd/nginx-deploy.tf new file mode 100644 index 0000000..66bb22a --- /dev/null +++ b/tf-modulised/kubernetes/sshd/nginx-deploy.tf @@ -0,0 +1,66 @@ +resource "kubernetes_deployment" "nginx" { + metadata { + name = "scalable-nginx-example" + labels = { + App = "ScalableNginxExample" + } + } + + spec { + replicas = 2 + selector { + match_labels = { + App = "ScalableNginxExample" + } + } + template { + metadata { + labels = { + App = "ScalableNginxExample" + } + } + spec { + container { + image = "nginx:latest" + name = "example" + + port { + container_port = 60080 + } + + resources { + limits { + cpu = "0.5" + memory = "512Mi" + } + requests { + cpu = "250m" + memory = "50Mi" + } + } + } + } + } + } +} + +resource "kubernetes_service" "nginx" { + metadata { + name = "nginx-example" + } + spec { + selector = { + App = kubernetes_deployment.nginx.spec.0.template.0.metadata[0].labels.App + } + port { + port = 60080 + target_port = 60080 + } + + type = "LoadBalancer" + } +} + +output "lb_ip" { + value = kubernetes_service.nginx.load_balancer_ingress[0].ip +} diff --git a/tf-modulised/kubernetes/sshd/nginx-pod.tf b/tf-modulised/kubernetes/sshd/nginx-pod.tf deleted file mode 100644 index 1c12704..0000000 --- a/tf-modulised/kubernetes/sshd/nginx-pod.tf +++ /dev/null @@ -1,20 +0,0 @@ -resource "kubernetes_pod" "nginx" { - metadata { - name = "nginx-example" - labels = { - App = "nginx" - } - } - - spec { - container { - image = "nginx:latest" - name = "example" - - port { - container_port = 9080 - } - } - } -} -