Feedback

Chat Icon

Helm in Practice

Designing, Deploying, and Operating Kubernetes Applications at Scale

Setting up the Environment
14%

The Platform

Our target platform, where everything will be deployed, is a Kubernetes cluster using K3s. We will set up the cluster in this section.

The K3s Server (Master Node)

Start by SSHing into the master node:

ssh root@$MASTER_PRIVATE_IP

Install K3s on the master node using the following command:

# Start by getting the external IP of the master node
MASTER_EXTERNAL_IP=$(curl -s http://ifconfig.me)

# Install K3s
curl -sfL https://get.k3s.io | \
    INSTALL_K3S_VERSION="v1.33.5+k3s1" sh -s - \
    server \
    --write-kubeconfig-mode '0644' \
    --node-external-ip "$MASTER_EXTERNAL_IP"

K3s should be installed and running. A kubeconfig file should be created at /etc/rancher/k3s/k3s.yaml. We will copy this file to the local machine so that we can use it to interact with the cluster.

# Create the kubeconfig directory
mkdir -p $HOME/.kube

# Create a symlink from the /etc/rancher/k3s/k3s.yaml file to the $HOME/.kube/config file
ln -s /etc/rancher/k3s/k3s.yaml $HOME/.kube/config

# Add auto-completion to the kubectl command
echo "source <(kubectl completion bash)" >> $HOME/.bashrc
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -o default -F __start_kubectl k' >>~/.bashrc

# Reload the bashrc file
source $HOME/.bashrc

You can now test the connection to the cluster.

kubectl get nodes

You should see the master node listed as Ready.

When the master node is launched, a token is created that will be used by the worker nodes to join the cluster. You can find this token in the following file:

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

We will use this token in the next section.

The K3s Agent (Worker Node)

Next, we will install K3s on the worker node, but before that, we need to SSH into the worker node.

ssh root@$WORKER_PRIVATE_IP

Save the token from the master node in a variable for later use:

TOKEN=$(ssh root@$MASTER_PRIVATE_IP cat /var/lib/rancher/k3s/server/node-token)

Run the following commands:

# Get the external IP of the worker node
WORKER_EXTERNAL_IP=$(curl -s http://ifconfig.me)

# Install K3s on the worker node
curl -sfL https://get.k3s.io | \

Helm in Practice

Designing, Deploying, and Operating Kubernetes Applications at Scale

Enroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!

Unlock now  $15.99$11.99

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More