From e5c9ff472f179427af43fc398bdc02f55310fda1 Mon Sep 17 00:00:00 2001 From: Matt Morrison Date: Tue, 2 Oct 2018 10:32:03 +1300 Subject: [PATCH] Add examples Deployment + StatefulSet --- _examples/deployment/main.tf | 43 ++++++++++++++ _examples/stateful_set/main.tf | 59 +++++++++++++++++++ kubernetes/test-infra/kops-on-aws/main.tf | 13 ++-- kubernetes/test-infra/kops-on-gce/main.tf | 11 ++-- .../test-infra/minikube-on-packet/main.tf | 29 +++++---- 5 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 _examples/deployment/main.tf create mode 100644 _examples/stateful_set/main.tf diff --git a/_examples/deployment/main.tf b/_examples/deployment/main.tf new file mode 100644 index 0000000000..836cddcc5d --- /dev/null +++ b/_examples/deployment/main.tf @@ -0,0 +1,43 @@ +resource "kubernetes_deployment" "httpbin" { + metadata { + name = "httpbin" + } + + spec { + selector { + foo = "bar" + app = "amaze" + } + + template { + metadata { + labels { + foo = "bar" + app = "amaze" + } + + annotations { + "prometheus.io/scrape" = "true" + } + } + + spec { + container { + image = "citizenstig/httpbin" + name = "app" + + port { + container_port = "8000" + } + + readiness_probe { + http_get { + path = "/healthz" + port = "8000" + } + } + } + } + } + } +} diff --git a/_examples/stateful_set/main.tf b/_examples/stateful_set/main.tf new file mode 100644 index 0000000000..54c6c62133 --- /dev/null +++ b/_examples/stateful_set/main.tf @@ -0,0 +1,59 @@ +resource "kubernetes_stateful_set" "test" { + metadata { + name = "test" + } + + spec { + replicas = 2 + + selector { + app = "httpbin" + } + + service_name = "test" + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + template { + metadata { + labels { + app = "httpbin" + } + } + + spec { + container { + image = "citizenstig/httpbin" + name = "httpbin" + + volume_mount { + name = "pvc" + mount_path = "/data" + } + } + } + } + + volume_claim_templates { + metadata { + name = "pvc" + } + + spec { + access_modes = ["ReadWriteOnce"] + + resources { + requests { + storage = "2Gi" + } + } + } + } + } +} diff --git a/kubernetes/test-infra/kops-on-aws/main.tf b/kubernetes/test-infra/kops-on-aws/main.tf index f40554f9a3..bca687d928 100644 --- a/kubernetes/test-infra/kops-on-aws/main.tf +++ b/kubernetes/test-infra/kops-on-aws/main.tf @@ -1,4 +1,4 @@ -provider "aws" { } +provider "aws" {} variable "route53_zone" { type = "string" @@ -9,12 +9,12 @@ variable "kubernetes_version" { } variable "s3_bucket_prefix" { - type = "string" + type = "string" default = "kops-tfacc" } variable "private_ssh_key_filename" { - type = "string" + type = "string" default = "id_rsa" } @@ -23,8 +23,8 @@ resource "random_id" "name" { } locals { - cluster_name = "${random_id.name.hex}.kops.${var.route53_zone}" - bucket_name = "${var.s3_bucket_prefix}-${random_id.name.hex}" + cluster_name = "${random_id.name.hex}.kops.${var.route53_zone}" + bucket_name = "${var.s3_bucket_prefix}-${random_id.name.hex}" public_ssh_key_location = "${path.module}/${var.private_ssh_key_filename}.pub" } @@ -35,7 +35,7 @@ data "http" "ipinfo" { } resource "tls_private_key" "ssh" { - algorithm = "RSA" + algorithm = "RSA" } resource "null_resource" "kops" { @@ -54,6 +54,7 @@ EOF provisioner "local-exec" { when = "destroy" + command = < /tmp/client/local-ip.txt", "cp -r ~/.minikube/{ca.crt,client.crt,client.key} /tmp/${var.dotminikube_path}/", ] @@ -124,8 +130,9 @@ ssh -i ${var.private_ssh_key_location} -o StrictHostKeyChecking=no -o ControlMas root@${packet_device.minikube.access_public_ipv4} >./tunnel.stdout.log 2>./tunnel.stderr.log EOF } + provisioner "local-exec" { - when = "destroy" + when = "destroy" command = "ssh -i ${var.private_ssh_key_location} -S tunnel-ctrl.socket -O exit root@${packet_device.minikube.access_public_ipv4}" } }