First uninstall snapd (causes issues sometimes):
sudo apt purge -y snapdThere are some OS packages which can be useful:
-
gparted- a graphical partition editor for creating, deleting, resizing, moving, checking, and copying disk partitions and the file systems on them. -
openssh-server- a secure shell (SSH) server which allows secure remote access to the system. -
git- needed for install linuxbrew (homebrew on linux). -
firefox- a web browser.
sudo apt update
sudo apt install -y gparted openssh-server git firefox curl build-essential/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"Install Azure CLI:
brew install azure-cli-
Each node needs to have a distinct
hostname. Ifhostnameis distinct, we can skip theK3S_NODE_NAMEparameter below (in both server and agent installation commands). -
INSTALL_K3S_SKIP_SELINUX_RPMis needed to avoid SELinux installation. -
K3S_KUBECONFIG_MODEis needed to set the kubeconfig file permissions. By default, it is600, but we need to set it to644so that it can be copied to other machines. -
INSTALL_K3S_EXECis needed to disable traefik and enable secrets encryption.
This is the control plane node.
curl -sfL https://get.k3s.io | K3S_NODE_NAME="k3s-control-plane" K3S_KUBECONFIG_MODE="644" INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_EXEC='server --secrets-encryption --disable traefik' sh -Meaning of each parameter:
curl -sfL https://get.k3s.io | \\
K3S_NODE_NAME="k3s-control-plane" \\ // (1)
K3S_KUBECONFIG_MODE="644" \\ // (2)
INSTALL_K3S_SKIP_SELINUX_RPM=true \\ // (3)
INSTALL_K3S_EXEC='server \\ // (4)
--secrets-encryption \\ // (5)
--disable traefik' \\ // (6)
sh --
K3S_NODE_NAMEis the name of the node. If not provided, the hostname will be used. -
K3S_KUBECONFIG_MODEis the permission mode for the kubeconfig file. By default, it is600, but we need to set it to644so that it can be copied to other machines. -
INSTALL_K3S_SKIP_SELINUX_RPMis needed to avoid SELinux installation. -
INSTALL_K3S_EXEChas various other options.servermeans this will be the control plane node. -
--secrets-encryptionis needed to enable secrets encryption. -
--disable traefikis needed to disable traefik (the default ingress controller / application proxy gateway).
Verify the installation:
sudo k3s kubectl get nodes
sudo k3s kubectl get pods -ACopy the default kubeconfig to the default location, and update the IP address to the node’s IP address:
mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config // (1)
sudo chown "$(id -u)":"$(id -g)" ~/.kube/config // (2)
NODE_IP="$(hostname -I | awk '{print $1}')" // (3)
sed -i "s/127.0.0.1/$NODE_IP/g" ~/.kube/config // (4)-
Copy the k3s kubeconfig to the default kubeconfig location.
-
Change the ownership of the kubeconfig file to the current user.
-
Get the primary IP address of the node.
-
Update the kubeconfig file with the node’s IP address (instead of
127.0.0.1). This is needed so that the kubeconfig can be used from other machines.
After this, kubectl get pods -A should work too since ~/.kube/config is now pointing to the k3s server. sudo is not needed for this command since we changed the ownership of the kubeconfig file.
This kubeconfig can now be copied to any machine which has line-of-sight to the k3s server, and can be used with kubernetes clients
To create a multi-node cluster, we need to note down a few values from the server node:
-
The server node’s IP address
NODE_IP="$(hostname -I | awk '{print $1}')" echo $NODE_IP
-
The server node’s token
K3S_TOKEN=$(sudo cat /var/lib/rancher/k3s/server/node-token)
This is the worker node (name: worker-node-1).
NODE_NAME="worker-node-1" // (1)
NODE_IP="<NODE_IP>" // (2)
K3S_TOKEN="<K3S_TOKEN>" // (3)
curl -sfL https://get.k3s.io | K3S_NODE_NAME="$K3S_NODE_NAME" INSTALL_K3S_SKIP_SELINUX_RPM=true K3S_URL="https://$NODE_IP:6443" K3S_TOKEN="$K3S_TOKEN" sh --
NODE_NAMEis the name of the node. If not provided, the hostname will be used. -
NODE_IPis the IP address of the server node (noted in the previous step). -
K3S_TOKENis the token of the server node (noted in the previous step).
Install the Azure CLI extensions:
az extension add --name connectedk8s
az extension add --name k8s-extension
az extension add --name customlocationLogin to Azure:
az login --tenant "<tenant-id>" --use-device-codeConnect the cluster to Azure:
|
Note
|
|
az connectedk8s connect --location <location> --resource-group <resource-group-name> --name <cluster-name> --kube-config ~/.kube/config