Full setup of a Kubernetes K3D cluster managed by Flux on a local Git server

Dito Medio
2 min readApr 25, 2022

For my fellow developer collegues, I needed a way for them to act on their machines the same way we (in the DevOps team) do when interacting with cloud Kubernetes clusters: using IAC and GitOps principles, pushing changes to a git repository monitored by WeaveWorks Flux.

They already use a K3D local cluster with our software components deployed, but changes to resources are applied to cluster via a bunch of bash scripts. I wanted to standardize our procedures and have them work the same way we do, obviously with some (many) adaptions: they don’t need to know all the details of the infrastructure, and of course they don’t need all the redundancies we apply to have resiliency and redundancy.

So, I thought to create an online IAC template repo, which is cloned locally, customized and pushed to a fully local git server, which is then used to bootstrap Flux on a local K3D cluster. After this, all changes to resources on the local git repo are monitored by Flux and applied to the K3D cluster. And developers just need to interact with these resources via git.

I created a script than will automaGically create a single node Kubernetes K3D cluster on your development machine (tested on MacOS), managed in GitOps way by Flux, which will interact with a fully local Git server running in a Docker container (external to the cluster). This all started as a Github Gist here.

To test it, clone my repo and run “bash k3d_local_git.sh”, go have a coffee, and back in 3 minutes you’ll have all installed and configured (plus a demo deployment, Stefan Prodan’s podinfo). If you want, you can use it in interactive mode passing “-d” switch on the command line.

On March 17, 2022 a live session of the interactive mode was taken and recorded by Kingdon Barrett (Open Source Support Engineer at Weaveworks), which collaborated by refactoring and reviewing the script code, so many thanks to him! :)

Youtube recording of the live session on the interactive mode
Youtube recording of the live session on the interactive mode.
An Asciinema recording of the full setup in unuttended mode.
An Asciinema recording of the full setup in unuttended mode.

--

--