Kubernetes & GitOps

Inception of Things: K3s & Argo CD

A Kubernetes and GitOps lab: K3s clusters provisioned with Vagrant, hostname-based ingress routing, and continuous delivery with K3d and Argo CD.

Last updated:

Inception of Things: K3s & Argo CD

Introduction

Inception of Things is a 42 infrastructure project that builds Kubernetes up in four stages: a two-node K3s cluster on virtual machines, a single node serving three applications behind ingress, a K3d cluster where Argo CD deploys an application straight from Git, and a bonus stage that replaces GitHub with a Gitea server running inside the cluster.

Every stage comes up with a single command, vagrant up for the VM-based parts and a setup script for the K3d parts, and the repository documents the concepts, the network layout, and a step-by-step GitOps demo.

The problem

Hand-built clusters drift. When nodes are configured manually and applications are deployed with one-off kubectl commands, nobody can say exactly what is running, rebuilding the environment takes hours, and every release depends on whoever is typing.

The goal was to make the whole path, from virtual machines to a running application, declarative and repeatable, and to make Git the single source of truth for what is deployed, so that a commit is all it takes to ship a new version.

Architecture

Parts 1 and 2 run on Debian VirtualBox machines provisioned by Vagrant on a private network. In Part 1 the controller (192.168.56.110) runs K3s in server mode and the worker (192.168.56.111) joins it as an agent with a shared token. In Part 2 a single K3s node runs three applications, and one Ingress resource routes app1.com and app2.com by Host header and sends every other host to app3, with app2 scaled to three replicas.

Part 3 and the bonus run K3s inside Docker with K3d. The cluster maps localhost:8888 to the application and localhost:9090 to the Argo CD UI through Traefik. Argo CD runs in the argocd namespace and watches a Git repository of manifests, while the application runs in the dev namespace. In the bonus, Gitea is installed in its own namespace with Helm, and Argo CD pulls from it over cluster-internal DNS, so the whole delivery loop stays inside the cluster.

Implementation decisions

K3s on VMs, K3d for GitOps
K3s provides a real multi-node cluster on modest VMs for the networking stages. K3d runs the same distribution in Docker containers, so the GitOps stages can be torn down and recreated in seconds.
Keep the built-in Traefik ingress
K3s and K3d ship with Traefik, so the Ingress rules target it directly instead of adding a second controller. That means fewer moving parts and the same routing behavior in every stage.
Pull-based GitOps with prune and self-heal
The Argo CD Application uses automated sync with prune and selfHeal enabled: resources removed from Git are deleted from the cluster, and manual changes are reverted to the state in Git.
TLS terminated at the ingress
The Argo CD server runs in insecure (HTTP) mode behind Traefik's HTTPS entrypoint. This avoids a redirect loop between the two and exposes the UI on https://localhost:9090.
Idempotent, ordered setup scripts
The scripts run with set -euo pipefail, install k3d when it is missing, delete any previous cluster, create namespaces idempotently, and wait for Argo CD and Gitea to become ready before applying anything that depends on them.

Technical challenges

  • Making the worker join reliably, which meant waiting for the controller API on port 6443 to be reachable before installing the agent
  • Exposing Argo CD behind Traefik without redirect loops, solved by terminating TLS at the ingress
  • Letting Argo CD reach a Git server hosted in the same cluster through internal service DNS rather than the host network
  • Sequencing installation steps so that nothing is applied before its dependencies are running

Results

  • Each stage rebuilds from scratch with a single command
  • Shipping a new version is a Git commit: changing the image tag from v1 to v2 in the watched repository updates the app on localhost:8888 without any kubectl command
  • Drift is corrected automatically: manual edits are reverted and deleted manifests are pruned
  • The bonus runs the full delivery loop, from Git server to CD controller to workloads, inside one local cluster
  • Documentation covers K3s versus K3d, the GitOps flow, Traefik routing, and the commands needed to debug each stage

Related case studies