Infrastructure as Code (IaC): Terraform & Terragrunt Regarding Kubernetes, I am using K3d as a local Kubernetes environment. Helm helps me to deploy a fully fledged Loki for logs, Prometheus and Grafana for monitoring.
Using Terraform, one is able to deliver infrastructure as code. With Terraform, I am able to control the whole stack and to keeping track of all changes within. I really like the convenience that Terraform offers when working on cloud-based infrastructure.
I'm using Terragrunt on top of Terraform to handle environments. You can have different environments, each with it's own configuration without repeating yourself (DRY).
With tfenv and tgenv I keep track of what version of Terraform and Terragrunt to work with. As I work on a Mac, I'm using Brew to install dependencies
brew install tfenv tgenv
tfenv install && tgenv install
All you need for having Kubernetes on your local machine is Docker, k3d and Kubectl to interact with.
As I use nginx as my ingress controller, I needed to disable Traefik on K3D.
The cluster's load balancer will be available via ports 80 and 443
k3d cluster create -p "80:80@loadbalancer" -p "443:443@loadbalancer" --k3s-arg="--disable=traefik@server:0"
For the sake of having some ears and eyes for what's going on there on our cluster, we need some monitoring:
Install Kube Prometheus Stack for cluster monitoring.
helm install -n monitoring -f terraform/modules/monitoring/config/monitoring.yaml kube-prometheus-stack prometheus-community/kube-prometheus-stack
When your k3d backed Kubernetes is ready, you're also ready to deploy the stack using Terragrunt.
cd environment/dev && terragrunt apply -auto-approve
To make usage of the ingress, I added the following /etc/hosts
127.0.0.1 grafana.localhost
127.0.0.1 prometheus.localhost
127.0.0.1 dashboard.localhost
127.0.0.1 wordpress.localhost
http://prometheus.localhost http://grafana.localhost
Create a user token: kubectl -n kube-dashboard create token admin-user
Your local Kubernetes based wordpress installation should now be available here