Installing K3S in an LXC container

Kevin Goos
3 min readJul 1, 2022

--

Proxmox + LXC + Kubernetes

In the previous part I informed everybody on how I setup an LXC container in Proxmox ready to install Docker and Kubernetes. Now in this tutorial I will take you through the installation of Docker and after that K3S which is a lightweight kubernetes cluster.

Why K3S over K8S

K3S is a lightweight kubernetes version which is created by rancher. Here we get all the basic components we need, and K3S can almost run on any device. So the perfect choise for my cluster.

Setup K3S

So now that we have an LXC container we can start with the installation. But the same installation will apply to a VM is you choise to go that way. After all the preperations we did in part 1, it is just one simple command:

curl -sfL https://get.k3s.io | sh -s - server --disable servicelb --disable traefik --write-kubeconfig-mode 644

Setup default config for server

Now the cluster is running, but we need to export the config so that the kubectl running on the server, knows where it need to go:

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

After this command we can start executing kubectl commands. To test is we execute the following command, and hopefully we get the response expected:

kubectl get nodes
Output

Setup kubectl on local windows shell

We don’t want to connect to the shell from the server all the time. So we setup the local shell to run kubectl commands on the server through the kubernetes API.

To install kubectl on you’re local computer, I used chocolaty package manager to install it. But there are also standalone binary’s. I will not explain how to install it, but point you to the documentation to find you’re way off working: https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/

So we have to get the current config from the server, and apply it to you’re personal computer. The following command will show the config if you run it on you’re server:

cat /etc/rancher/k3s/k3s.yaml

This command will output a config that you then can copy to you’re local computer:

apiVersion: v1
clusters:
- cluster:
certificate-authority-data: [some-key]
server: https://127.0.0.1:6443
name: default
contexts:
- context:
cluster: default
user: default
name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
user:
client-certificate-data: [some-other-key]

So we need to create a file called config inside the following location: C:\users\[user]\.kube

If the folder .kube doesn’t exist yet, you can just create it yourself.

Importanted to change the server address from https://127.0.0.1:6443 to the correct IP address from the server where it need to connect to. (Example: https://192.168.1.50:6443)

Install helm (on local machine)

Helm is an easy CLI used to install and deploy kubernetes pods. We will install this here, but use it in the next parts of the tutorial to install prepared packages, easier.

curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm

Finally

Now we have a working basic cluster where we can deploy pods. But the next problem will be, how we give access to pods from the outside. So in the next part we will start setting up a loadbalancer so that we can get adresses assigned to the pods.

Next chapter:

https://kevingoos.medium.com/installing-k3s-in-an-lxc-container-2fc24b655b93

--

--

Kevin Goos

Currently I am freelance .NET developer. After work I also love to put some time in managing my own servers and services.