This repo contains scripts to setup a kubernetes cluster with 3 nodes untainted. It is fully automated and installs the following:
- Kubernetes (via kubeadm)
- Cilium (CNI)
- Traefik (Ingress)
- Certmanager (TLS certificates)
- Socat binary and a script (for port forwarding)
- Longhorn (Storage)
- 3 Servers
- Debain 12
- Root access
- Domain
- Be able to set DNS records
- Local machine
- kubectl
- helm
First prepare your nodes:
- Debain 12
- Add your ssh key to the
authorized_keys
file on the root - Make sure all hosts are in your known hosts file
Create control plane endpoint:
Create a sub domain for your control plane endpoint.
Create an A record for the sub domain pointing to the first node.
After the setup you can add A records for all nodes.
Then configure the bootstrap script by setting the env vars:
# Username and Password of the new user
export NEW_USER='jonasbe'
export PW='abc'
# Control plane endpoint
export CP_ENDPOINT='cp.k8s.jonasbe.de:6443'
# Cluster name
export CLUSTER_NAME='jk8s'
# Email for Let's Encrypt
export EMAIL='[email protected]'
# Servers to setup
# it musst be the domain to connect and the hostname of a server
# the first server is the node which runs kubeadm init
export SERVERS='nc1.jonasbe.de nc2.jonasbe.de nc3.jonasbe.de'
After configuring the setup, execute the script:
./bootstrap.sh
- Create a new user
- Move ssh keys to new user and remove from root
- Update the system
- Install containerd
- Install kubeadm, kubelet and kubectl
Runs on the first node you configured
- Create a kubeadm config file
- Kubeadm init with the created config file
- Copy the kubeconfig file to the new user
- Runs
upload-certs
via kubeadm - Generate a join command
- Combines the certs from step 1 and the join command from step 2 and uses it to join the node
- Install cilium cli on master node
- Install cilium CNI command
All nodes get untainted, so that pods can be scheduled on them.
To forward ports to a node port, it uses socat.
By default it forwards port 80 and 443 to the nodeports configure in the Traefik deployment.
- Install socat and screen
- Start a screen session's (you have start them after every reboot)
How to start the forwarding manually:
./start-forward.sh
- Install Traefik via helm
- Install certmanager
- Wait 10s to let certmanager get ready
- Apply letsencrypt clusterissuer, for tls certificates
- Prepare the nodes for longhorn
- Install longhorn via helm
Edit the traefik/whoami/whoami.yaml
file and change the domain to your domain.
Make sure the domain is pointing to all of your servers.
Then apply the manifest kubectl apply -f traefik/whoami/whoami.yaml
.