Initial master node

The following section will explain how to deploy the initial master node of the k3s cluster.

Install kubectl CLI tool

In order to test and manage the k3s cluster, it could be useful to have a kubectl cli install in the master nodes:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

# Test it
kubectl version --client

Auto-complete

Use the following commands to add auto-completion to your bash shell for the kubectl command (or it’s k alias)

echo 'source <(kubectl completion bash)' >>~/.bashrc
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc

Deploy

# enable read for other users
export K3S_KUBECONFIG_MODE=0644

# Deploy a new k3s master node with embeded etcd
curl -sfL https://get.k3s.io | sh -s - --disable=traefik --cluster-init

Configuration file

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

You can test the connection to the cluster by listing the deployed pods and the list of nodes in the cluster (only one will be listed by now):

kubectl get pods --all-namespaces
kubectl get nodes

#Output:
NAME          STATUS   ROLES                       AGE     VERSION
k3s-mstr-01   Ready    control-plane,etcd,master   2m32s   v1.20.2+k3s1

Retrieve the cluster token

This token will be used to join the other nodes to the current k3s deployment:

sudo cat /var/lib/rancher/k3s/server/node-token