NEW: terraform and kubernetes

This commit is contained in:
xpk 2020-07-28 17:02:15 +08:00
parent 29bcb2fca2
commit 4326717c19
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
2 changed files with 66 additions and 20 deletions

View File

@ -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
}

View File

@ -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
}
}
}
}