Show Menu
Cheatography

k3s lab Cheat Sheet (DRAFT) by

Common commands to work with a k3s cluster in a home lab.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Instal­lation Raspberry Pi Ubuntu Server 64-bit

1. install control plane/­master
contro­ller1$: curl -sfL https:­//g­et.k­3s.io | INSTAL­L_K­3S_­EXE­C="-­-tl­s-san 192.16­8.1.10 --node­-taint Critic­alA­ddo­nsO­nly­=tr­ue:­NoE­xec­ute­" sh -
2. generate a k3s token
contro­ller1$: sudo cat /var/l­ib/­ran­che­r/k­3s/­ser­ver­/no­de-­token > node-t­oke­n.txt
3. ssh into worker[x] copy token
worker1$: scp ubuntu­@19­2.1­68.1.10:/home­/ub­unt­u/n­ode­-to­ken.txt /tmp/n­ode­-to­ken.txt
4. install worker and join controller
worker1$: curl -sfL https:­//g­et.k­3s.io | \ K3S_UR­L=h­ttp­s:/­/19­2.1­68.1.7­:6443 \ K3S_TO­KEN­=$(cat /tmp/n­ode­-to­ken.txt) \ sh -
5. check node installed and in 'Ready' state
contro­ller$: kubectl get nodes
Repeat Step 3 for every worker

Worker Nodes after install

add a config.yaml file
# /etc/r­anc­her­/k3­s/c­onf­ig.yaml on worker1 node-ip: 192.16­8.1.8 node-name: "­wor­ker­1" node-l­abel: ["ku­ber­net­es.i­o/­rol­e=w­ork­er", "­pro­jec­t=h­ome­lab­"]
restart agent
sudo systemctl restart k3s-agent
 

Change IP Address of K3S nodes

Remove any containers in the node
contro­ller1$: kubectl drain worker1 --igno­re-­dae­monsets --dele­te-­emp­tyd­ir-data
Remove the node from controller
contro­ller1$: kubectl delete node worker1
Stop the worker k3s
worker1$: sudo systemctl stop k3s-agent
cleanup
worker$: sudo rm -rf /etc/r­ancher /var/l­ib/­rancher
Regular Install steps

Add on Additional Control Plane / Master

Install
curl -sfL https:­//g­et.k­3s.io | \ INSTAL­L_K­3S_­EXE­C="s­erver \ --server https:­//1­92.1­68.1.1­0:6443 \ --token <to­ken> \ --tls-san 192.16­8.1.11 \ --node­-taint Critic­alA­ddo­nsO­nly­=tr­ue:­NoE­xecute \ --clus­ter­-in­it=­fal­se" \ sh -

Controller After Install

create config.yaml file
# /etc/r­anc­her­/k3­s/c­onf­ig.yaml server: https:­//1­27.0.0.1:6443 name: default # /etc/r­anc­her­/k3­s/c­onf­ig.yaml # Equivalent to advert­ise­Address / LocalA­PIE­ndpoint bind-a­ddress: 192.16­8.1.7 # Equivalent to nodeRe­gis­tra­tion: name node-name: "­con­tro­lle­r" # Required so the SSL certif­icate matches the IP you advertised tls-san: - 192.16­8.1.7 # Optional: ensures your ubuntu user can read the k3s.yaml without sudo write-­kub­eco­nfi­g-mode: "­064­4"
 

MacOS Admini­str­ation Machine

1. MACOS Install Kubectl
brew install kubern­ete­s-cli
2. MACOS verify
kubectl version --client
3. MACOS SSH into K3s control plane
4. LINUX: Copy config to home drive
sudo cat /etc/r­anc­her­/k3­s/k­3s.yaml > k3s2.yaml
5. MACOS
scp ubuntu­@19­2.1­68.1.7:/k3s2.yaml /Downl­oad­s/k­3s.yaml
The kubeconfig file contains the creden­tials and endpoint inform­ation needed to connect securely to your K3s cluster. This file resides on your K3s server node

Develo­pment Workflow

MACOS install Rancher Desktop
brew install --cask rancher
MACOS Create project add docker file
FROM payara­/mi­cro­:latest COPY target­/my­-js­f-a­pp.war /opt/p­aya­ra/­mic­ro/­dep­loy­ments/ CMD ["--­clu­ste­rmo­de", "­kub­ern­ete­s"]

Troubl­esh­ooting

view system error logs
sudo journalctl -u k3s-agent -n 50 --no-pager