{"id":13678761,"url":"https://github.com/ahgraber/homelab-gitops-k3s","last_synced_at":"2026-02-01T02:18:52.735Z","repository":{"id":37021249,"uuid":"393171908","full_name":"ahgraber/homelab-gitops-k3s","owner":"ahgraber","description":"k3s cluster managed by FluxCD GitOps","archived":false,"fork":false,"pushed_at":"2024-10-29T13:26:52.000Z","size":10638,"stargazers_count":64,"open_issues_count":11,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-29T16:04:46.189Z","etag":null,"topics":["gitops","k3s","k8s-at-home","kubernetes","kubesearch","self-hosted"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahgraber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-05T21:13:50.000Z","updated_at":"2024-10-29T13:26:21.000Z","dependencies_parsed_at":"2023-09-29T02:51:54.897Z","dependency_job_id":"e646602c-c534-45d6-97ec-c466cd1598ec","html_url":"https://github.com/ahgraber/homelab-gitops-k3s","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":"onedr0p/cluster-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahgraber%2Fhomelab-gitops-k3s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahgraber%2Fhomelab-gitops-k3s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahgraber%2Fhomelab-gitops-k3s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahgraber%2Fhomelab-gitops-k3s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahgraber","download_url":"https://codeload.github.com/ahgraber/homelab-gitops-k3s/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224179093,"owners_count":17269000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitops","k3s","k8s-at-home","kubernetes","kubesearch","self-hosted"],"created_at":"2024-08-02T13:00:57.970Z","updated_at":"2026-02-01T02:18:52.729Z","avatar_url":"https://github.com/ahgraber.png","language":"Shell","funding_links":[],"categories":["Python","Shell"],"sub_categories":[],"readme":"# Homelab cluster with k3s and Flux\n\nThis repo configures a single Kubernetes ([k3s](https://k3s.io)) cluster with [Ansible](https://www.ansible.com) and uses the GitOps tool [Flux](https://toolkit.fluxcd.io) to manage its state.\n\n## ✨ Features\n\n- Automated, reproducible, customizable setup through Ansible templates and playbooks\n- Opinionated implementation of Flux from the [Home Operations Community's template](https://github.com/onedr0p/flux-cluster-template/tree/main#-help)\n- Encrypted secrets with [SOPS](https://github.com/getsops/sops) and [Age](https://github.com/FiloSottile/age)\n- Web application firewall provided by [Cloudflare Tunnels](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/)\n- SSL certificates from [Cloudflare](https://cloudflare.com) and [cert-manager](https://cert-manager.io)\n- HA control plane capability via [kube-vip](https://kube-vip.io)\n- Next-gen networking using [Cilium](https://cilium.io/)\n- A [Renovate](https://www.mend.io/renovate)-ready repository with pull request diffs provided by [flux-local](https://github.com/allenporter/flux-local)\n- Integrated [GitHub Actions](https://github.com/features/actions)\n\n... and more!\n\n## 📝 Prerequisites\n\n- [ ] A domain managed on Cloudflare.\n- [ ] A DNS server that supports split DNS (e.g., Pi-hole) deployed somewhere outside your cluster **on** your home network.\n\n## 🚀 Installation\n\n### 📍 Set up your local environment\n\n1. Install [task](https://taskfile.dev/).\n\n2. Install [direnv](https://direnv.net/).\n\n3. Install [pipx](https://pipx.pypa.io/stable/), then ensure hooks are set with:\n\n   ```sh\n   pipx ensurepath\n   pipx completions\n   ```\n\n4. Finish configuring the workstation.\\\n   Conveniently, we can use a `task` that has been defined for this.\n\n   ```sh\n   task workstation:setup\n   ```\n\n   \u003e This command will install ansible in a pipx environment, then use brew to install other necessary binaries like\n   \u003e [age](https://github.com/FiloSottile/age), [flux](https://toolkit.fluxcd.io/), [cloudflared](https://github.com/cloudflare/cloudflared),\n   \u003e [kubectl](https://kubernetes.io/docs/tasks/tools/), and [sops](https://github.com/getsops/sops)\n\n### 🔧 Initial configuration\n\n1. Set up Age private/public key\n\n   📍 _Using [SOPS](https://github.com/getsops/sops) with [Age](https://github.com/FiloSottile/age) allows us to encrypt secrets and use them in Ansible and Flux._\n\n   a.\n   Create an Age private/public key (this file is gitignored)\n\n   ```sh\n   age-keygen -o age.key\n   ```\n\n   b.\n   Ensure that this key is available as an environment variable.\n\n   Add the following to the `.envrc`:\n\n   ```sh\n   # export SOPS_AGE_KEY_FILE=\"$(expand_path \"${HOME}/Library/Application Support/sops/age/keys.txt\")\"\n   export SOPS_AGE_KEY_FILE=\"$(expand_path \"${HOME}/.config/sops/age/keys.txt\")\"\n   export AGE_PUBLIC_KEY=\"$(grep \"public key\" \"$SOPS_AGE_KEY_FILE\" | awk '{ print $4 }')\"\n   ```\n\n   Then run `direnv allow .` to refresh the environment.\n\n2. Create Cloudflare API Token\n\n   📍 _To use `cert-manager` with the Cloudflare DNS challenge you will need to create an API token._\n\n   1. [Create a Cloudflare API Token here](https://dash.cloudflare.com/profile/api-tokens).\n\n   2. Under the `API Tokens` section click the blue `Create Token` button.\n\n   3. Click the blue `Use template` button for the `Edit zone DNS` template.\n\n   4. Name your token something like `flux-system`\n\n   5. Under `Permissions`, click `+ Add More` and add each permission below:\n\n      ```text\n      Zone - DNS - Edit\n      Account - Cloudflare Tunnel - Read\n      ```\n\n   6. Limit the permissions to a specific account and zone resources.\n\n   7. Fill out the appropriate vars in `.env` file:\n\n      ```sh\n      CLOUDFLARE_EMAIL=''\n      CLOUDFLARE_TOKEN=''\n      CLOUDFLARE_ACCOUNT=''\n      CLOUDFLARE_TUNNELID=''\n      CLOUDFLARE_TUNNEL_SECRET=''\n      ```\n\n3. Create Cloudflare Tunnel\n\n   📍 _To expose services to the internet you will need to create a [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/)._\n\n   1. Authenticate cloudflared to your domain\n\n      ```sh\n      cloudflared tunnel login\n      ```\n\n   2. Create the tunnel\n\n      ```sh\n      cloudflared tunnel create k8s\n      ```\n\n   3. Fill out the appropriate Cloudflare Tunnel vars in the `.env` file: CLOUDFLARE_ACCOUNT, CLOUDFLARE_TUNNELID, CLOUDFLARE_TUNNEL_SECRET\n\n   \u003e Cloudflare Tunnel info can be found with `cat ~/.cloudflared/*.json | jq -r`.\n\n### ⚡ Prepare your nodes for k3s\n\n📍 _Here we will be running an Ansible playbook to prepare your nodes for running a Kubernetes cluster._\n\n1. Ensure you are able to SSH into your nodes from your workstation using a private SSH key **without a passphrase** (for example using a SSH agent).\n   This lets Ansible interact with your nodes.\n\n2. Verify Ansible can view your config\n\n   ```sh\n   task ansible:hosts\n   ```\n\n3. Verify Ansible can ping your nodes\n\n   ```sh\n   task ansible:ping\n   ```\n\n4. Run the Ansible prepare playbook (nodes will reboot when done)\n\n   ```sh\n   task ansible:prepare\n   ```\n\n### 🛰️ Build your k3s cluster with Ansible\n\n📍 _Here we will be running a Ansible Playbook to install [k3s](https://k3s.io/) with [this](https://galaxy.ansible.com/xanmanning/k3s) Ansible galaxy role._\n\n\u003e If you run into problems, you can run `task k3s:nuke` to destroy the k3s cluster and start over from this point.\n\n1. Verify Ansible can view your config\n\n   ```sh\n   task ansible:hosts\n   ```\n\n2. Verify Ansible can ping your nodes\n\n   ```sh\n   task ansible:ping\n   ```\n\n3. Install k3s (may need to run this twice to pass the k3s systemd restart)\n\n   ```sh\n   task k3s:install\n   ```\n\n   \u003e The `kubeconfig` for interacting with your cluster should have been created in the root of your repository.\n\n4. Verify the nodes are online\n\n   ```sh\n   kubectl get nodes -o wide\n   # NAME           STATUS   ROLES                       AGE     VERSION\n   # k8s-0          Ready    control-plane,etcd,master   1h      v1.27.3+k3s1\n   # k8s-1          Ready    worker                      1h      v1.27.3+k3s1\n   ```\n\n5. Review the pods currently running in the cluster\n\n   ```sh\n   kubectl get pods -A -o wide\n   ```\n\n### 🔹 Install Flux in your cluster\n\n1. Verify Flux can be installed\n\n   ```sh\n   flux check --pre\n   # ► checking prerequisites\n   # ✔ kubectl 1.27.3 \u003e=1.18.0-0\n   # ✔ Kubernetes 1.27.3+k3s1 \u003e=1.16.0-0\n   # ✔ prerequisites checks passed\n   ```\n\n2. Push your changes to git\n\n   📍 **Verify** all the `*.sops.yaml` files under the `./ansible` and `./kubernetes` directories are **encrypted** with SOPS\n\n   ```sh\n   git add -A\n   git commit -m \"Initial commit :rocket:\"\n   git push\n   ```\n\n3. Install Flux and sync the cluster to the Git repository\n\n   ```sh\n   task flux:bootstrap\n   # namespace/flux-system configured\n   # customresourcedefinition.apiextensions.k8s.io/alerts.notification.toolkit.fluxcd.io created\n   # ...\n   ```\n\n4. Verify Flux components are running in the cluster\n\n   ```sh\n   kubectl -n flux-system get pods -o wide\n   # NAME                                       READY   STATUS    RESTARTS   AGE\n   # helm-controller-5bbd94c75-89sb4            1/1     Running   0          1h\n   # kustomize-controller-7b67b6b77d-nqc67      1/1     Running   0          1h\n   # notification-controller-7c46575844-k4bvr   1/1     Running   0          1h\n   # source-controller-7d6875bcb4-zqw9f         1/1     Running   0          1h\n   ```\n\n### ☑️ Verification Steps\n\n1. Output all the common resources in your cluster.\n\n   📍 _Suggestion: Use the provided [tasks](.taskfiles/) for validation of cluster resources or continue to get familiar with the `kubectl` and `flux` CLI tools._\n\n   ```sh\n   task k8s:resources\n   ```\n\n2. ⚠️ It might take `cert-manager` a while to generate certificates, this is normal so be patient.\n\n## 📣 Post installation\n\n### 🌐 Public DNS\n\nThe `external-dns` application created in the `networking` namespace will handle creating public DNS records.\nBy default, `echo-server` and the `flux-webhook` are the only subdomains reachable from the public internet.\nIn order to make additional applications public you must set the correct ingress class name and ingress annotations like in the HelmRelease for `echo-server`.\n\n### 🏠 Home DNS\n\n`k8s_gateway` will provide DNS resolution to external Kubernetes resources (i.e. points of entry to the cluster) from any device that uses your home DNS server.\nFor this to work, your home DNS server must be configured to forward DNS queries for `\u003ccloudflare_domain\u003e` to `\u003ck8s_gateway_addr\u003e` instead of the upstream DNS server(s) it normally uses.\nThis is a form of **split DNS** (aka split-horizon DNS / conditional forwarding).\n\n\u003e [!TIP]\n\u003e Below is how to configure a Pi-hole for split DNS. Other platforms should be similar.\n\u003e\n\u003e 1. Apply this file on the server\n\u003e\n\u003e    ```sh\n\u003e    # /etc/dnsmasq.d/99-k8s-gateway-forward.conf\n\u003e    server=/${bootstrap_cloudflare_domain}/${bootstrap_k8s_gateway_addr}\n\u003e    ```\n\u003e\n\u003e 2. Restart dnsmasq on the server.\n\u003e\n\u003e 3. Query an internal-only subdomain from your workstation (any `internal` class ingresses): `dig @${home-dns-server-ip} hubble.${bootstrap_cloudflare_domain}`. It should resolve to `${bootstrap_internal_ingress_addr}`.\n\nIf you're having trouble with DNS be sure to check out these two GitHub discussions: [Internal DNS](https://github.com/onedr0p/flux-cluster-template/discussions/719) and [Pod DNS resolution broken](https://github.com/onedr0p/flux-cluster-template/discussions/635).\n\n...\nNothing working?\nThat is expected, this is DNS after all!\n\n#### 📜 Certificates\n\nBy default this template will deploy a wildcard certificate using the Let's Encrypt **staging environment**, which prevents you from getting rate-limited by the Let's Encrypt production servers if your cluster doesn't deploy properly (for example, due to a misconfiguration).\nOnce you are sure you will keep the cluster up for more than a few hours, be sure to switch to the production servers as outlined in `config.yaml`.\n\n📍 _You will need a production certificate to reach internet-exposed applications through `cloudflared`._\n\n#### 🪝 GitHub Webhook\n\nBy default Flux will periodically check your git repository for changes.\nIn order to have Flux reconcile on `git push` you must configure GitHub to send `push` events.\n\n1. Follow [FluxCD instructions](https://fluxcd.io/flux/guides/webhook-receivers/#define-a-git-repository-receiver) to generate a token.\n\n2. Obtain the webhook path\n\n   📍 _Hook id and path should look like `/hook/123abc123abc...`_\n\n   ```sh\n   kubectl -n flux-system get receiver github-webhook -o jsonpath='{.status.webhookPath}'\n   ```\n\n3. Piece together the full URL with the webhook path appended\n\n   ```text\n   https://flux-webhook.${bootstrap_cloudflare_domain}/hook/123abc123abc...\n   ```\n\n4. Navigate to the settings of your repository on GitHub, under \"Settings/Webhooks\" press the \"Add webhook\" button.\n   Fill in the webhook url and your `bootstrap_flux_github_webhook_token` secret and save.\n\n### 🤖 Renovate\n\n[Renovate](https://www.mend.io/renovate) is a tool that automates dependency management.\nIt is designed to scan your repository around the clock and open PRs for out-of-date dependencies it finds.\nCommon dependencies it can discover are Helm charts, container images, GitHub Actions, Ansible roles... even Flux itself!\nMerging a PR will cause Flux to apply the update to your cluster.\n\nTo enable Renovate, click the 'Configure' button over at their [GitHub app page](https://github.com/apps/renovate) and select your repository.\nRenovate creates a \"Dependency Dashboard\" as an issue in your repository, giving an overview of the status of all updates.\nThe dashboard has interactive checkboxes that let you do things like advance scheduling or reattempt update PRs you closed without merging.\n\nThe base Renovate configuration in your repository can be viewed at [.github/renovate.json5](https://github.com/onedr0p/flux-cluster-template/blob/main/.github/renovate.json5).\nBy default it is scheduled to be active with PRs every weekend, but you can [change the schedule to anything you want](https://docs.renovatebot.com/presets-schedule), or remove it if you want Renovate to open PRs right away.\n\n## 🐛 Debugging\n\nBelow is a general guide on trying to debug an issue with a resource or application.\nFor example, if a workload/resource is not showing up or a pod has started but is in a `CrashLoopBackOff` or `Pending` state.\n\n1. Start by checking all Flux Kustomizations \u0026 Git Repository \u0026 OCI Repository and verify they are healthy.\n\n   ```sh\n   flux get sources oci -A\n   flux get sources git -A\n   flux get ks -A\n   ```\n\n2. Then check all the Flux Helm Releases and verify they are healthy.\n\n   ```sh\n   flux get hr -A\n   ```\n\n3. Then check if the pod is present.\n\n   ```sh\n   kubectl -n \u003cnamespace\u003e get pods -o wide\n   ```\n\n4. Then check the logs of the pod if it's there.\n\n   ```sh\n   kubectl -n \u003cnamespace\u003e logs \u003cpod-name\u003e -f\n   # or\n   stern -n \u003cnamespace\u003e \u003cfuzzy-name\u003e\n   ```\n\n5. If a resource exists try to describe it to see what problems it might have.\n\n   ```sh\n   kubectl -n \u003cnamespace\u003e describe \u003cresource\u003e \u003cname\u003e\n   ```\n\n6. Check the namespace events\n\n   ```sh\n   kubectl -n \u003cnamespace\u003e get events --sort-by='.metadata.creationTimestamp'\n   ```\n\nResolving problems that you have could take some tweaking of your YAML manifests in order to get things working, other times it could be an external factor like permissions on NFS.\nIf you are unable to figure out your problem see the help section below.\n\n### Authenticate Flux over SSH\n\nAuthenticating Flux to your git repository has a benefits like using a private git repository and/or using the Flux [Image Automation Controllers](https://fluxcd.io/docs/components/image/).\n\nBy default this template only works on a public GitHub repository, it is advised to keep your repository public.\n\nThe benefits of a public repository include:\n\n- When debugging or asking for help, you can provide a link to a resource you are having issues with.\n- Adding a topic to your repository of `k8s-at-home` to be included in the [k8s-at-home-search](https://nanne.dev/k8s-at-home-search/).\n  This search helps people discover different configurations of Helm charts across other Flux-based repositories.\n\n\u003c!-- markdownlint-disable MD033 --\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eExpand to read guide on adding Flux SSH authentication\u003c/summary\u003e\n\u003c!-- markdownlint-enable MD033 --\u003e\n\n01. Generate new SSH key:\n\n    ```sh\n    ssh-keygen -t ecdsa -b 521 -C \"github-deploy-key\" -f ./kubernetes/bootstrap/github-deploy.key -q -P \"\"\n    ```\n\n02. Paste public key in the deploy keys section of your repository settings\n\n03. Create sops secret in `./kubernetes/bootstrap/github-deploy-key.sops.yaml` with the contents of:\n\n    ```yaml\n    apiVersion: v1\n    kind: Secret\n    metadata:\n      name: github-deploy-key\n      namespace: flux-system\n    stringData:\n      # 3a. Contents of github-deploy-key\n      identity: |\n        -----BEGIN OPENSSH ... -----\n            ...\n        -----END OPENSSH ... -----\n      # 3b. Output of curl --silent https://api.github.com/meta | jq --raw-output '\"github.com \"+.ssh_keys[]'\n      known_hosts: |\n        github.com ssh-ed25519 ...\n        github.com ecdsa-sha2-nistp256 ...\n        github.com ssh-rsa ...\n    ```\n\n04. Encrypt secret:\n\n    ```sh\n    sops --encrypt --in-place ./kubernetes/bootstrap/github-deploy-key.sops.yaml\n    ```\n\n05. Apply secret to cluster:\n\n    ```sh\n    sops --decrypt ./kubernetes/bootstrap/github-deploy-key.sops.yaml | kubectl apply -f -\n    ```\n\n06. Update `./kubernetes/flux/config/cluster.yaml`:\n\n    ```yaml\n    apiVersion: source.toolkit.fluxcd.io/v1beta2\n    kind: GitRepository\n    metadata:\n    name: flux-system\n    namespace: flux-system\n    spec:\n    interval: 10m\n    # 6a: Change this to your user and repo names\n    url: ssh://git@github.com/$user/$repo\n    ref:\n      branch: main\n    secretRef:\n      name: github-deploy-key\n    ```\n\n07. Commit and push changes\n\n08. Force flux to reconcile your changes\n\n    ```sh\n    flux reconcile -n flux-system kustomization cluster --with-source\n    ```\n\n09. Verify git repository is now using SSH:\n\n    ```sh\n    flux get sources git -A\n    ```\n\n10. Optionally set your repository to Private in your repository settings.\n\n\u003c!-- markdownlint-disable MD033 --\u003e\n\n\u003c/details\u003e\n\u003c!-- markdownlint-enable MD033 --\u003e\n\n## 🤝 Thanks\n\nThis would not be possible without onedr0p and the k8s-at-home community!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahgraber%2Fhomelab-gitops-k3s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahgraber%2Fhomelab-gitops-k3s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahgraber%2Fhomelab-gitops-k3s/lists"}