Everyone can contribute! Let's learn together in a weekly cafe ☕

We love to break things, make mistakes, debug, analyse, fix problems together. Live and unfiltered on Youtube.

Community members and thought leaders regularly join and share their projects and ideas.

"Everyone Can Contribute" is inspired by GitLab's mission.

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


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:



Enjoy the session! 🦊

Date published: April 7, 2021

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