Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
Deployment + StatefulSet
  • Loading branch information
sl1pm4t committed Oct 1, 2018
1 parent d243f43 commit e5c9ff4
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 22 deletions.
43 changes: 43 additions & 0 deletions _examples/deployment/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
59 changes: 59 additions & 0 deletions _examples/stateful_set/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
13 changes: 7 additions & 6 deletions kubernetes/test-infra/kops-on-aws/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
provider "aws" { }
provider "aws" {}

variable "route53_zone" {
type = "string"
Expand All @@ -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"
}

Expand All @@ -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"
}

Expand All @@ -35,7 +35,7 @@ data "http" "ipinfo" {
}

resource "tls_private_key" "ssh" {
algorithm = "RSA"
algorithm = "RSA"
}

resource "null_resource" "kops" {
Expand All @@ -54,6 +54,7 @@ EOF

provisioner "local-exec" {
when = "destroy"

command = <<EOF
export CLUSTER_NAME=${local.cluster_name}
export BUCKET_NAME=${local.bucket_name}
Expand Down
11 changes: 6 additions & 5 deletions kubernetes/test-infra/kops-on-gce/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ variable "zone_name" {
}

variable "bucket_prefix" {
type = "string"
type = "string"
default = "kops-tfacc"
}

variable "private_ssh_key_filename" {
type = "string"
type = "string"
default = "id_rsa"
}

Expand All @@ -21,10 +21,10 @@ resource "random_id" "name" {
}

locals {
cluster_name = "k.${random_id.name.hex}.${var.zone_name}"
bucket_name = "${var.bucket_prefix}-${random_id.name.hex}"
cluster_name = "k.${random_id.name.hex}.${var.zone_name}"
bucket_name = "${var.bucket_prefix}-${random_id.name.hex}"
public_ssh_key_location = "${path.module}/${var.private_ssh_key_filename}.pub"
tmp_creds_location = "${path.module}/google-creds.json"
tmp_creds_location = "${path.module}/google-creds.json"
}

data "google_compute_zones" "available" {}
Expand All @@ -50,6 +50,7 @@ EOF

provisioner "local-exec" {
when = "destroy"

command = <<EOF
export TMP_CREDS_PATH=${local.tmp_creds_location}
export CLUSTER_NAME=${local.cluster_name}
Expand Down
29 changes: 18 additions & 11 deletions kubernetes/test-infra/minikube-on-packet/main.tf
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
provider "packet" { }
provider "packet" {}

variable "kubernetes_version" {
type = "string"
type = "string"
description = "See 'minikube get-k8s-versions' for all available versions"
}

variable "packet_facility" {
type = "string"
type = "string"
description = "See https://www.packet.net/developers/api/facilities/ for all available facilities"
default = "ams1"
default = "ams1"
}

variable "packet_plan" {
type = "string"
type = "string"
description = "See https://www.packet.net/developers/api/plans/ for all available plans"
default = "baremetal_1"
default = "baremetal_1"
}

variable "local_tunnel_port" {
type = "string"
type = "string"
default = "32000"
}

variable "kubernetes_api_port" {
type = "string"
type = "string"
default = "8443"
}

variable "private_ssh_key_location" {
type = "string"
type = "string"
default = "./id_ecdsa"
}

variable "dotminikube_path" {
type = "string"
type = "string"
default = "client/.minikube"
}

Expand Down Expand Up @@ -75,15 +75,18 @@ resource "packet_device" "minikube" {
user = "root"
private_key = "${tls_private_key.ssh.private_key_pem}"
}

source = "${path.module}/10-install-virtualbox.sh"
destination = "/tmp/10-install-virtualbox.sh"
}

provisioner "file" {
connection {
type = "ssh"
user = "root"
private_key = "${tls_private_key.ssh.private_key_pem}"
}

source = "${path.module}/20-install-minikube.sh"
destination = "/tmp/20-install-minikube.sh"
}
Expand All @@ -94,13 +97,16 @@ resource "packet_device" "minikube" {
user = "root"
private_key = "${tls_private_key.ssh.private_key_pem}"
}

inline = [
"chmod a+x /tmp/10-install-virtualbox.sh && chmod a+x /tmp/20-install-minikube.sh",
"/tmp/10-install-virtualbox.sh | tee /var/log/provisioning-10-virtualbox.log",
"/tmp/20-install-minikube.sh | tee /var/log/provisioning-20-minikube.log",
"minikube start --kubernetes-version=v${var.kubernetes_version}",

# Extract certs so they can be transfered back to client
"mkdir -p /tmp/${var.dotminikube_path}",

"minikube ip | tr -d \"\n\" > /tmp/client/local-ip.txt",
"cp -r ~/.minikube/{ca.crt,client.crt,client.key} /tmp/${var.dotminikube_path}/",
]
Expand All @@ -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}"
}
}
Expand Down

0 comments on commit e5c9ff4

Please sign in to comment.