My latest version of Kubernetes config deployed in my home lab. Managed flux and terraform for gitops.
  • HCL 88.9%
  • Nix 11.1%
Find a file
flux 3cc3bbd958 🚀 banterbus: Automated image update
📦 Files updated:
- migration-prod.yaml
- prod.yaml
🔄 Image changes:
- prod-4faeb3c479080bca2bb89bf4af575b2ea603b83a-1761857693 -> prod-18197451181de83b2ebf8d71d7ce9cfc5ab1caae-1763325865
- prod-4faeb3c479080bca2bb89bf4af575b2ea603b83a-1761857693 -> prod-18197451181de83b2ebf8d71d7ce9cfc5ab1caae-1763325865
2025-11-16 20:44:57 +00:00
.gitlab/agents/k8s Update kubeconfig 2025-09-14 18:12:09 +01:00
clusters 🚀 banterbus: Automated image update 2025-11-16 20:44:57 +00:00
infra/tf fix: remove old vault secret references from cloudflare-tunnel kustomization 2025-10-27 20:30:42 +00:00
.envrc Initial commit: Flux GitOps setup with OpenTofu 2025-09-07 22:54:48 +01:00
.gitignore Add Tailscale support (skip pre-commit for now) 2025-09-10 15:59:32 +01:00
.pre-commit-config.yaml fix: update banterbus dev node selector to match cluster labels 2025-10-25 23:20:33 +01:00
.yamllint Add Traefik CRD definitions and fix flux-webhook ingress 2025-11-16 19:33:30 +00:00
flake.lock Initial commit: Flux GitOps setup with OpenTofu 2025-09-07 22:54:48 +01:00
flake.nix Complete infrastructure and configuration updates 2025-09-12 08:05:36 +01:00
README.md fix: issues on the cluster 2025-10-27 18:18:28 +00:00
renovate.json Configure Renovate 2025-09-16 21:20:17 +01:00

K8s GitOps with Flux and OpenTofu

Simple GitOps setup following k3s-config patterns.

Setup

nix develop
# or
direnv allow
cp terraform/terraform.tfvars.example terraform/terraform.tfvars

Edit with your GitLab token and project details.

cd terraform
tofu init
tofu apply

Structure

├── dev/                    # Dev namespace
├── prod/                   # Prod namespace
├── apps/                   # Applications (repo-per-app pattern)
│   ├── namespace.yaml      # Apps namespace
│   ├── sources/            # Git sources for external repos
│   └── banterbus/          # Banterbus app (points to banterbus/banterbus repo)
├── clusters/              # Flux bootstrap point
└── terraform/              # Bootstrap configuration

Manual step

To setup homelab some commands need to be run manually for now until we can move it into terraform/automate it.

GitLab

Create a PAT in GitLab

# Create a GitLab Personal Access Token with these scopes:
# - 'api' (for preview environments, webhooks, MR access)
# - 'read_repository' (for cloning, branch access)
# - 'write_repository' (for Flux GitOps commits)
# - 'read_user' (for MR author info in preview environments)

Tailscale

Create the following tags in your policy

"tagOwners": {
   "tag:k8s-operator": [],
   "tag:k8s": ["tag:k8s-operator"],
}

Create an OAuth client in the OAuth clients page of the admin console. Create the client with Devices Core and Auth Keys write scopes, and the tag tag:k8s-operator.

Then manually add it to k8s

kubectl create secret generic operator-oauth -n tailscale \
        --from-literal=client_id=$TAILSCALE_CLIENT_ID  \
        --from-literal=client_secret=$TAILSCALE_CLIENT_SECRET

Potentially solved using init container with host network, assuming host is already on tailnet

OpenBao

Setup the terraform policy and user and password manually so it can configure everything else we need with openbao.

Potentially solved with this: https://openbao.org/docs/rfcs/self-init/#proof-of-concept

Grafana

Create a terraform service account.

TODO

  • bugsink to use postgres

  • Migrate to use quic2 for tunnel

  • kubernetes_secret.gitlab_api_token created in terraform get it to use openbao having issues with VaultStaticSecret.

  • traefik token and cert in nixicle

# Get the token
kubectl get secret traefik-token -n kube-system -o jsonpath='{.data.token}' | base64 -d

# Get the CA certificate
kubectl get secret traefik-token -n kube-system -o jsonpath='{.data.ca\.crt}' | base64 -d

# Get the server URL
kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'