rust84 / k8s-gitops

Kubernetes cluster with Flux and Renovate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My Homelab Repository :octocat:

... automated via Flux, Renovate and GitHub Actions πŸ€–

Discord   Kubernetes   Renovate

Home Internet   Home-Assistant   Plex

Age-Days   Uptime-Days   Node-Count   Pod-Count   CPU-Usage   Memory-Usage   Power-Usage


πŸ“– Overview

This is a repository for my home infrastructure and Kubernetes cluster. I try to adhere to Infrastructure as Code (IaC) and GitOps practices using tools like Terraform, Kubernetes, Flux, Renovate and GitHub Actions.


β›΅ Kubernetes

There is a template over at onedr0p/flux-cluster-template if you wanted to try and follow along with some of the practices I use here.

Installation

This semi hyper-converged cluster runs Talos Linux, an immutable and ephemeral Linux distribution built for Kubernetes, deployed on bare-metal Intel NUCs. Rook then provides my workloads with persistent block, object, and file storage; while a seperate server provides file storage for my media.

πŸ”Έ Click here to see my Talos configuration.

Core Components

  • cilium: Internal Kubernetes networking plugin.
  • cert-manager: Creates SSL certificates for services in my Kubernetes cluster.
  • external-dns: Automatically manages DNS records from my cluster in a cloud DNS provider.
  • external-secrets: Managed Kubernetes secrets using Doppler.
  • ingress-nginx: Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer.
  • rook: Distributed block storage for peristent storage.
  • sops: Managed secrets for Kubernetes and Terraform which are commited to Git.
  • volsync: Backup and recovery of persistent volume claims.

GitOps

Flux watches the clusters in my kubernetes folder (see Directories below) and makes the changes to my clusters based on the state of my Git repository.

The way Flux works for me here is it will recursively search the k8s/clusters/${cluster} folder until it finds the most top level kustomization.yaml per directory and then apply all the resources listed in it. That aforementioned kustomization.yaml will generally only have a namespace resource and one or many Flux kustomizations. Those Flux kustomizations will generally have a HelmRelease or other resources related to the application underneath it which will be applied.

Renovate watches my entire repository looking for dependency updates, when they are found a PR is automatically created. When some PRs are merged Flux applies the changes to my cluster.

Directories

This Git repository contains the following directories under Kubernetes.

πŸ“ k8s
β”œβ”€β”€ πŸ“ cluster/cluster-0  # main cluster
β”‚   β”œβ”€β”€ πŸ“ crds         # custom resources
β”‚   β”œβ”€β”€ πŸ“ flux           # core flux configuration
β”‚   └── πŸ“ manifests      # applications
└── πŸ“ global/flux      # shared resources
    β”œβ”€β”€ πŸ“ repositories   # helm and git repositories
    β”œβ”€β”€ πŸ“ vars           # common variables
    └── πŸ“ flux           # core flux configuration

Flux Workflow

This is a high-level look how Flux deploys my applications with dependencies. Below there are 3 apps postgres, authentik and weave-gitops. postgres is the first app that needs to be running and healthy before authentik and weave-gitops. Once postgres is healthy authentik will be deployed and after that is healthy weave-gitops will be deployed.

graph TD;
  id1>Kustomization: cluster] -->|Creates| id2>Kustomization: cluster-apps];
  id2>Kustomization: cluster-apps] -->|Creates| id3>Kustomization: postgres];
  id2>Kustomization: cluster-apps] -->|Creates| id6>Kustomization: authentik]
  id2>Kustomization: cluster-apps] -->|Creates| id8>Kustomization: weave-gitops]
  id2>Kustomization: cluster-apps] -->|Creates| id5>Kustomization: postgres-cluster]
  id3>Kustomization: postgres] -->|Creates| id4[HelmRelease: postgres];
  id5>Kustomization: postgres-cluster] -->|Depends on| id3>Kustomization: postgres];
  id5>Kustomization: postgres-cluster] -->|Creates| id10[Postgres Cluster];
  id6>Kustomization: authentik] -->|Creates| id7(HelmRelease: authentik);
  id6>Kustomization: authentik] -->|Depends on| id5>Kustomization: postgres-cluster];
  id8>Kustomization: weave-gitops] -->|Creates| id9(HelmRelease: weave-gitops);
  id8>Kustomization: weave-gitops] -->|Depends on| id5>Kustomization: postgres-cluster];
  id9(HelmRelease: weave-gitops) -->|Depends on| id7(HelmRelease: authentik);

☁️ Cloud Dependencies

While most of my infrastructure and workloads are self-hosted I do rely upon the cloud for certain key parts of my setup. This saves me from having to worry about two things. (1) Dealing with chicken/egg scenarios and (2) services I critically need whether my cluster is online or not.

The alternative solution to these two problems would be to host a Kubernetes cluster in the cloud and deploy applications like Vaultwardenand Uptime Kuma. However, maintaining another cluster and monitoring another group of workloads is a lot more time and effort than I am willing to put in.

Service Use Cost
Cloudflare Domain and S3 ~$30/yr
GitHub Hosting this repository and continuous integration/deployments Free
NextDNS My router DNS server which includes AdBlocking ~$20/yr
Fly.io I have two small machines running here which host my password manager and Uptime Kuma Free (total spend is below $5)

πŸ”§ Hardware

Device Count OS Disk Size Data Disk Size Ram Operating System Purpose
Intel NUC8i3BEH 1 500GB SSD 500GB SSD NVMe (rook-ceph) 64GB Talos OS Control-plane/Worker
Intel NUC8i5BEH 2 500GB SSD 500GB SSD NVMe (rook-ceph) 64GB Talos OS Control-plane/Workers
PowerEdge R720 1 256GB SSD 3x18TB ZFS (borg pool) 2x2TB Mirror (apps) 64GB TrueNAS NFS + Backup Server
PiKVM (Arch) Network KVM
TESmart 8 Port KVM Switch 1 - - - - Network KVM (PiKVM)
AliExpress Topton J6413 1 128GB NVMe - 8GB OPNsense Router
Unifi USW-24-Pro 1 - - - - Core Switch
APC SMT2200RM2U w/ NIC 1 - - - - UPS

⭐ Stargazers

Star History Chart


🀝 Gratitude and Thanks

Thanks to all the people who donate their time to the Home Operations Discord community. Be sure to check out kubesearch.dev for ideas on how to deploy applications or get ideas on what you may deploy.


πŸ“œ Changelog

See my awful commit history


πŸ” License

See LICENSE

About

Kubernetes cluster with Flux and Renovate

License:Do What The F*ck You Want To Public License


Languages

Language:Shell 59.2%Language:Jinja 40.8%