Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding the Kubernetes Provider for Terraform

Understanding the Kubernetes Provider for Terraform

In this talk, Taylor Dolezal (Developer Advocate at HashiCorp) and I look at how to use Terraform to create Kubernetes Namespaces, Deployments and Services using Terraform.

This version of the presentation was given at an internal event in August 2020.

Kerim Satirli
PRO

August 11, 2020
Tweet

More Decks by Kerim Satirli

Other Decks in Programming

Transcript

  1. Copyright © 2020 HashiCorp Understanding the Kubernetes Provider For Terraform

  2. Kerim Satirli (He/Him) Developer Advocate at HashiCorp

  3. @ksatirli on GitHub and Twitter Developer Advocate at HashiCorp

  4. Taylor Dolezal (He/Him) Developer Advocate at HashiCorp

  5. @onlydole on GitHub and Twitter Developer Advocate at HashiCorp

  6. Introduction to Terraform

  7. Infrastructure as Code ▪ executable documentation ▪ enables collaboration ▪

    safe and predictable
  8. Terraform 135+ Official Providers AWS, GCP, Datadog, etc. 200+ Community

    Providers 1Password, Stripe, Unifi, etc.
  9. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  10. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:${var.port}" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  11. Kubernetes Namespaces everything has a home Services exposes Deployments Deployments

    declarative updates Nodes machines
  12. None
  13. None
  14. None
  15. Creating a Namespace CODE EDITOR resource "kubernetes_namespace" "beacon" { name

    = "beacon" metadata { name = "beacon" } }
  16. Creating a Deployment CODE EDITOR resource "kubernetes_deployment" "beacon" { metadata

    { name = "beacon" namespace = kubernetes_namespace.beacon.id spec { container { image = "onlydole/beacon:1.19.1" name = "beacon" } } }
  17. Creating a Service CODE EDITOR resource "kubernetes_service" "beacon" { metadata

    { name = "beacon" namespace = kubernetes_namespace.beacon.id spec { selector { app = kubernetes_deployment.beacon.metadata.0.labels.app } } ...
  18. Creating a Service CODE EDITOR ... port { port =

    8080 target_port = 80 } type = "LoadBalancer" }
  19. Command: terraform apply TERMINAL > terraform apply "kubernetes.tfplan" Apply complete!

    Resources: 3 added, 0 changed, 0 destroyed.
  20. Beacon your.app.url:8080

  21. Review ▪ Terraform and IaC ▪ Kubernetes Concepts ▪ Kubernetes

    Resources
  22. Thank You kerim@hashicorp.com and tdolezal@hashicorp.com