Skip to content

Latest commit

 

History

History
171 lines (123 loc) · 10 KB

InstallInstructions.md

File metadata and controls

171 lines (123 loc) · 10 KB

How I re-build once my cluster is up

Cluster Details/Original Text

Highly opinionated template for deploying a single k3s cluster with Ansible and Terraform backed by Flux and SOPS.

The purpose here is to showcase how you can deploy an entire Kubernetes cluster and show it off to the world using the GitOps tool Flux. When completed, your Git repository will be driving the state of your Kubernetes cluster. In addition with the help of the Ansible, Terraform and Flux SOPS integrations you'll be able to commit Age encrypted secrets to your public repo.

👋  Introduction

The following components will be installed in your k3s cluster by default. They are only included to get a minimum viable cluster up and running. You are free to add / remove components to your liking but anything outside the scope of the below components are not supported by this template.

Feel free to read up on any of these technologies before you get started to be more familiar with them.

For provisioning the following tools will be used:

  • Ubuntu - this is a pretty universal operating system that supports running all kinds of home related workloads in Kubernetes
  • Ansible - this will be used to provision the Ubuntu operating system to be ready for Kubernetes and also to install k3s
  • Terraform - in order to help with the DNS settings this will be used to provision an already existing Cloudflare domain and DNS settings

📝  Prerequisites

💻  Systems

  • One or more nodes with a fresh install of Ubuntu Server 20.04. These nodes can be bare metal or VMs.
  • A Cloudflare account with a domain, this will be managed by Terraform.
  • Some experience in debugging problems and a positive attitude ;)

🔧  Tools

📍 You should install the below CLI tools on your workstation. Make sure you pull in the latest versions.

Required

Tool Purpose
ansible Preparing Ubuntu for Kubernetes and installing k3s
direnv Exports env vars based on present working directory
flux Operator that manages your k8s cluster based on your Git repository
age A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.
go-task A task runner / simpler Make alternative written in Go
ipcalc Used to verify settings in the configure script
jq Used to verify settings in the configure script
kubectl Allows you to run commands against Kubernetes clusters
sops Encrypts k8s secrets with Age
terraform Prepare a Cloudflare domain to be used with the cluster

Optional

Tool Purpose
helm Manage Kubernetes applications
kustomize Template-free way to customize application configuration
pre-commit Runs checks pre git commit
gitleaks Scan git repos (or files) for secrets
prettier Prettier is an opinionated code formatter.

⚠️  pre-commit

It is advisable to install pre-commit and the pre-commit hooks that come with this repository. sops-pre-commit and gitleaks will check to make sure you are not by accident committing your secrets un-encrypted.

After pre-commit is installed on your machine run:

pre-commit install-hooks

📂  Repository structure

The Git repository contains the following directories under cluster and are ordered below by how Flux will apply them.

  • base directory is the entrypoint to Flux
  • crds directory contains custom resource definitions (CRDs) that need to exist globally in your cluster before anything else exists
  • core directory (depends on crds) are important infrastructure applications (grouped by namespace) that should never be pruned by Flux
  • apps directory (depends on core) is where your common applications (grouped by namespace) could be placed, Flux will prune resources here if they are not tracked by Git anymore
cluster
├── apps
│   ├── default
│   ├── networking
│   └── system-upgrade
├── base
│   └── flux-system
├── core
│   ├── cert-manager
│   ├── metallb-system
│   ├── namespaces
│   └── system-upgrade
└── crds
    └── cert-manager

🚀  Lets go!

Very first step will be to create a new repository by clicking the Use this template button on this page.

Clone the repo to you local workstation and cd into it.

📍 All of the below commands are run on your local workstation, not on any of your cluster nodes.

🔐  Setting up Age

📍 Here we will create a Age Private and Public key. Using SOPS with Age allows us to encrypt and decrypt secrets.

  1. Create a Age Private / Public Key
age-keygen -o age.agekey
  1. 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
  1. Export the SOPS_AGE_KEY_FILE variable in your bashrc, zshrc or config.fish and source it, e.g.
export SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt
source ~/.bashrc
  1. Fill out the Age public key in the .config.env under BOOTSTRAP_AGE_PUBLIC_KEY, note the public key should start with age...

Verify cluster

  1. Verify the nodes are online, after deploying the cluster with Sidero.
kubectl get 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

🔹  GitOps with Flux

  1. Bootstrap flux but don't deploy the full flux yet

  2. Disable the apps as needed for your cluster

  3. Install full flux and wait for everything to deploy flux get kustomization -A and after a bit flux get helmrelease -A

  4. Wait for rook to figure its life out for a bit. Usually within about 10 minutes it'll get everything needed setup, and the WebUI will come up.

watch kubectl -n rook-ceph get pods

If desired, login to the web UI with the password from:

kubectl -n rook-ceph get secret rook-ceph-dashboard-password -o jsonpath="{['data']['password']}" | base64 --decode && echo
  1. Node feature discovery will automatically label my nodes with the correct USB devices.

  2. Restore from backup with method of choice