chaijunkin / home-ops

K3s Cluster powered by proxmox
Do What The F*ck You Want To Public License
2 stars 0 forks source link
k8s-at-home
### My Homelab Repository :snowflake: _... automated via [Flux](https://fluxcd.io), [Renovate](https://github.com/renovatebot/renovate) and [GitHub Actions](https://github.com/features/actions)_ 🤖
[![Discord](https://img.shields.io/discord/673534664354430999?style=for-the-badge&label&logo=discord&logoColor=white&color=blue)](https://discord.gg/home-operations)   [![Kubernetes](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dkubernetes_version&style=for-the-badge&logo=kubernetes&logoColor=white&color=blue&label=%20)]()  
[![Status-Page](https://img.shields.io/endpoint?url=https%3A%2F%2Fstatus.cloudjur.com%2Fapi%2Fv1%2Fendpoints%2Fexternal_gatus%2Fhealth%2Fbadge.shields&style=for-the-badge&logo=statuspage&logoColor=white&label=Status%20Page)](https://status.cloudjur.com/endpoints/external_gatus)  
[![Age-Days](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_age_days&style=flat-square&label=Age)](https://github.com/kashalls/kromgo/)   [![Uptime-Days](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_uptime_days&style=flat-square&label=Uptime)](https://github.com/kashalls/kromgo/)   [![Node-Count](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_node_count&style=flat-square&label=Nodes)](https://github.com/kashalls/kromgo/)   [![Pod-Count](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_pod_count&style=flat-square&label=Pods)](https://github.com/kashalls/kromgo/)   [![CPU-Usage](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_cpu_usage&style=flat-square&label=CPU)](https://github.com/kashalls/kromgo/)   [![Memory-Usage](https://img.shields.io/endpoint?url=https%3A%2F%2Fkromgo.cloudjur.com%2Fquery%3Fformat%3Dendpoint%26metric%3Dcluster_memory_usage&style=flat-square&label=Memory)](https://github.com/kashalls/kromgo/)  

Overview

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

The purpose here is to learn k8s, while practicing Gitops.


⛵ Kubernetes

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

Installation

My cluster is k3s provisioned overtop bare-metal Debian using the Ansible galaxy role ansible-role-k3s. This is a semi-hyper-converged cluster, workloads and block storage are sharing the same available resources on my nodes while I have a separate NAS server with ZFS for NFS/SMB shares, bulk file storage and backups.

Core Components

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 kubernetes/apps 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.

📁 kubernetes
│── 📁 apps           # applications
│── 📁 bootstrap      # bootstrap procedures
│── 📁 flux           # core flux configuration
│── 📁 templates      # re-useable components

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 HCVault, Vaultwarden, ntfy, and Gatus. 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
Bitwarden Secrets with External Secrets ~$TBC/yr
Cloudflare Domain and S3 ~$TBC/yr
GitHub Hosting this repository and continuous integration/deployments Free
<!-- NextDNS My router DNS server which includes AdBlocking ~$20/yr -->
Uptimekuma Monitoring internet connectivity and external facing applications Free
Total: ~$TBC/mo

🔧 Hardware

Kubernetes Cluster

Name Device CPU OS Disk Data Disk RAM OS Purpose
master (VM) Dashy 4 50GB SSD None 16GB Debian k8s control-plane
worker (VM) Dashy 4 100GB SSD None 24GB Debian k8s worker

Total CPU: 8 threads Total RAM: 40GB

Supporting Hardware

Name Device CPU OS Disk Data Disk RAM OS Purpose
Dashy (host) Custom built E-2246G 64GB 500GB SSD 64GB Proxmox Virtualize NAS and VM
NAS (VM) Dashy 2 8G ZFS 4TB x2 (mirror) 512Mib Debian LXC NAS/NFS/Backup

Networking/UPS Hardware

Device Purpose
Mini PC (Aliexpress) Router
Omada Access point Access point
Netgear GS324P 8 Port 2.5G 10G Switch - Main
TP-link switch 8 Port 1G Switch - Sub
Dlink PoE Switch 8 Port 0.1G Poe Switch
UPS PROPOSING

⭐ Stargazers

[![Star History Chart](https://api.star-history.com/svg?repos=chaijunkin/home-ops&type=Date)](https://star-history.com/#chaijunkin/home-ops&Date)

🤝 Thanks

Big shout out to original flux-cluster-template, and 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