Setup Kubernetes Cluster k3
Posted on June 2, 2022
Tags: devops
1 Install docker
2 Install kubernetes master node
curl -sfL https://get.k3s.io | sh -
You will encounter an error:
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
If on homeserver, just follow instructions below, but note that doing do exposes the k3s.yaml file to other users on the server.
sudo sh -c "echo "K3S_KUBECONFIG_MODE=\"644\"" >> /etc/systemd/system/k3s.service.env"
sudo systemctl restart k3s
- kubectl, crictl, ctr, k3s-killall.sh, and k3s-uninstall.sh are installed
- kubeconfig is in /etc/rancher/k3s/k3s.yaml
3 Kube commands
kubectl get nodes
# NAME STATUS ROLES AGE VERSION
# debian Ready control-plane,master 8m19s v1.24.6+k3s1
3.1 Stopping Kubernetes Cluster
- The file came installed in your
/usr/local/bin/k3s-killall.sh
k3s-killall.sh
WARN: systemctl stop k3s
will not stop the pods/containers.
3.2 Starting Kubernetes Cluster
k3s server
or
sudo systemctl restart k3s
4 Kube worker
- get token
cat /var/lib/rancher/k3s/server/node-token
5 Autocomplete kube yaml
install kubernetes support on vscode.
type Kubernetes Deployment
6 k3
config
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config