k3s cluster deployed with Ansible, backed by Flux and SOPS.
- flux - GitOps operator for managing Kubernetes clusters from a Git repository
- kube-vip - Load balancer for the Kubernetes control plane nodes
- metallb - Load balancer for Kubernetes services
- cert-manager - Operator to request SSL certificates and store them as Kubernetes resources
- calico - Container networking interface for inter pod and service networking
- external-dns - Operator to publish DNS records to Cloudflare (and other providers) based on Kubernetes ingresses
- k8s_gateway - DNS resolver that provides local DNS to the Kubernetes ingresses
- traefik - Kubernetes ingress controller used for a HTTP reverse proxy of Kubernetes ingresses
- local-path-provisioner - provision persistent local storage with Kubernetes
Additional applications include hajimari, error-pages, echo-server, system-upgrade-controller, reflector, reloader, and kured
Provisioning is performed using Ansible.
The Git repository contains the following directories under cluster
and are ordered below by how Flux will apply them.
📁 cluster # k8s cluster defined as code
├─📁 flux # flux, gitops operator, loaded before everything
├─📁 crds # custom resources, loaded before 📁 core and 📁 apps
├─📁 charts # helm repos, loaded before 📁 core and 📁 apps
├─📁 config # cluster config, loaded before 📁 core and 📁 apps
├─📁 core # crucial apps, namespaced dir tree, loaded before 📁 apps
└─📁 apps # regular apps, namespaced dir tree, loaded last
Create a Age Private and Public key. Using SOPS with Age allows us to encrypt secrets and use them in Ansible and Flux.
-
Create a Age Private / Public Key
age-keygen -o age.agekey
-
Set up the directory for the Age key and move the Age file to it
mkdir -p ~/.config/sops/age mv age.agekey ~/.config/sops/age/keys.txt
-
Export the
SOPS_AGE_KEY_FILE
variable inbashrc
,zshrc
orconfig.fish
and source it, e.g.export SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt source ~/.bashrc
-
Fill out the Age public key in the
.config.env
underBOOTSTRAP_AGE_PUBLIC_KEY
, note the public key should start withage
The .config.env
file contains necessary configuration that is needed by Ansible and Flux.
-
Copy the
.config.sample.env
to.config.env
and start filling out all the environment variables:All are required unless otherwise noted in the comments.
cp .config.sample.env .config.env
-
Once that is done, verify the configuration is correct by running:
task verify
-
If you do not encounter any errors, wire up the templated files and place them where they need to be.
task configure
-
Ensure you are able to SSH into your nodes using a private SSH key without a passphrase.
-
Install the Ansible deps:
task ansible:init
-
Verify Ansible can view the config:
task ansible:list
-
Verify Ansible can ping the nodes:
task ansible:ping
-
Run the Ubuntu Prepare Ansible playbook:
task ansible:prepare
-
Reboot the nodes:
task ansible:reboot
☢️ If you run into problems, you can run task ansible:nuke
to destroy the k3s cluster and start over.
-
Verify Ansible can view your config:
task ansible:list
-
Verify Ansible can ping your nodes:
task ansible:ping
-
Install k3s with Ansible:
task ansible:install
-
Verify the nodes are online:
task cluster:nodes # NAME STATUS ROLES AGE VERSION # k8s-0 Ready control-plane,master 4d20h v1.21.5+k3s1 # k8s-1 Ready worker 4d20h v1.21.5+k3s1
-
Verify Flux can be installed:
task cluster:verify # ► checking prerequisites # ✔ kubectl 1.21.5 >=1.18.0-0 # ✔ Kubernetes 1.21.5+k3s1 >=1.16.0-0 # ✔ prerequisites checks passed
-
Install Flux and sync the cluster to the Git repository:
task cluster:install # namespace/flux-system configured # customresourcedefinition.apiextensions.k8s.io/alerts.notification.toolkit.fluxcd.io created
-
Verify Flux components are running in the cluster:
task cluster:pods -- -n flux-system # NAME READY STATUS RESTARTS AGE # helm-controller-5bbd94c75-89sb4 1/1 Running 0 1h # kustomize-controller-7b67b6b77d-nqc67 1/1 Running 0 1h # notification-controller-7c46575844-k4bvr 1/1 Running 0 1h # source-controller-7d6875bcb4-zqw9f 1/1 Running 0 1h
-
View the Flux Git Repositories:
task cluster:gitrepositories
-
View the Flux kustomizations:
task cluster:kustomizations
-
View all the Flux Helm Releases:
task cluster:helmreleases
-
View all the Flux Helm Repositories:
task cluster:helmrepositories
-
View all the Pods:
task cluster:pods
-
View all the certificates and certificate requests:
task cluster:certificates
-
View all the ingresses:
task cluster:ingresses
All the commands above can be run with one task:
task cluster:resources