Install k3s cluster
Prerequisites
- A load balancer IP or hostname.
- Access to all control plane and worker nodes.
Installation
-
Install NFS support (optional)
If your cluster will use NFS for persistent storage, install the
nfs-common
package on all nodes (both control plane and worker nodes) by running the following command:Terminal window sudo apt install nfs-common -
Install k3s on the first control plane node
Run the following command to install k3s:
Terminal window curl -sfL https://get.k3s.io | sh -s - server \--cluster-init \--node-taint CriticalAddonsOnly=true:NoExecute \--tls-san <load-balancer-ip-or-hostname> -
Retrieve the cluster token
After the installation, retrieve the
<cluster-token>
and take note of it:Terminal window cat /var/lib/rancher/k3s/server/node-token -
Install k3s on additional control plane nodes
Run the following command to install k3s and link it to the cluster:
Terminal window curl -sfL https://get.k3s.io | sh -s - server \--node-taint CriticalAddonsOnly=true:NoExecute \--tls-san <load-balancer-ip-or-hostname> \--server https://<control-plane-01-ip>:6443 \--token <cluster-token> -
Install k3s on all the worker nodes
Run the following command to install k3s and link it to the cluster:
Terminal window curl -sfL https://get.k3s.io | sh -s - agent \--server https://<control-plane-01-ip>:6443 \--token <cluster-token>
Configure local kubectl
access
-
Retrieve the Kubernetes configuration from one of the control plane nodes:
Terminal window sudo cat /etc/rancher/k3s/k3s.yaml -
Save the content to a file located at
%USERPROFILE%/.kube/<filename-without-extension>
on your local machine. Rename thedefault
context to your preferred cluster name. -
Add configuration to
kubectl
. In PowerShell, run:Terminal window Get-ChildItem -Path "$($env:USERPROFILE)/.kube" -File | ForEach-Object {$configFiles += $_.FullName + ";"}[Environment]::SetEnvironmentVariable("KUBECONFIG", $configFiles, "USER") -
Switch to the new context:
Terminal window kubectl config use-context <context-name>