Everyone is welcome, everyone can contribute, everyone is unique and these are your strengths too!

24. #everyonecancontribute cafe: Automate Kubernetes deployment with Terraform and GitLab CI/CD


Highlights

We are learning how to deploy and secure Kubernetes into Hetzner cloud in this series:

In this session, we automate the deployment of the Kubernetes cluster with Max inside GitLab CI/CD:

  • Automate the deployment from the repository with GitLab CI/CD
  • Preparations in GitLab: Add CI/CD variables and update settings.
    • Variable hcloud_token.
    • File SSH_KEY - GitLab reads the file.
    • Disable public pipeline to avoid leaking credentials in artifacts.
  • Define GitLab CI/CD pipeline stages:
    • test
    • terraform-diff
    • terraform
    • ansible-diff
    • ansible
    • kubeconfig
  • CI/CD rule with the pre-defined variable CI_PIPELINE_SOURCE to only allow triggers from web - single click deployments from the GitLab web interface.
  • Create a template job, starting with a dot and later imported with extends.
  • Import the .terraform job template into new Terraform jobs: TF Validate with gitlab-terraform init and gitlab-terraform validate. gitlab-terraform is a wrapper which sets config automatically. Infrastructure as Code with Terraform and GitLab docs.
  • Example worflow from the GitLab Terraform template.
  • Add more jobs: TF Plan and TF Apply.
  • Navigate into CI/CD > Pipelines and click Run pipeline for the main branch.

In the future, we’ll explore more Kubernetes topics:

Insights

Recording

Enjoy the session! 🦊


Date published: April 7, 2021

Tags: Gitlab, Hetzner, Cloud, Terraform, Ansible, Kubernetes, Security, Kiosk, Multi tenancy