Skip to content

Instantly share code, notes, and snippets.

@andrewsomething

andrewsomething/main.tf

Last active Dec 12, 2018
Embed
What would you like to do?
Terraform + DigitalOcean Kubernetes = <3
provider "digitalocean" {}
// Create a cluster on DigitalOcean
resource "digitalocean_kubernetes_cluster" "example" {
name = "example"
region = "nyc1"
version = "1.12.3-do.1"
node_pool {
name = "wokers"
size = "s-2vcpu-2gb"
node_count = 3
}
}
// Initiate the Kubernetes provider w/ DigitalOcean cluster creds
provider "kubernetes" {
host = "${digitalocean_kubernetes_cluster.example.endpoint}"
client_certificate = "${base64decode(digitalocean_kubernetes_cluster.example.kube_config.0.client_certificate)}"
client_key = "${base64decode(digitalocean_kubernetes_cluster.example.kube_config.0.client_key)}"
cluster_ca_certificate = "${base64decode(digitalocean_kubernetes_cluster.example.kube_config.0.cluster_ca_certificate)}"
}
// Create an Nginx deployment
resource "kubernetes_pod" "nginx" {
metadata {
name = "nginx-example"
labels {
App = "nginx"
}
}
spec {
container {
image = "nginx:1.15.7-alpine"
name = "example"
port {
container_port = 80
}
}
}
}
// Expose Nginx w/ a LoadBalancer service
resource "kubernetes_service" "nginx" {
metadata {
name = "nginx-example"
}
spec {
selector {
App = "${kubernetes_pod.nginx.metadata.0.labels.App}"
}
port {
port = 80
target_port = 80
}
type = "LoadBalancer"
}
}
output "lb_ip" {
value = "${kubernetes_service.nginx.load_balancer_ingress.0.ip}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.