Setup Local Kubernetes Development Environment
How to setup a local development environment for Kubernetes using K3S.
Last updated
Was this helpful?
How to setup a local development environment for Kubernetes using K3S.
Last updated
Was this helpful?
We assume kubectl is already installed on the local machine
First of all, to be able to develop for Kubernetes, we need to install its lightweight cousin called K3S :
Since we are going to use k3s for local development, its fine to enable access for the current logged in user additionaly to root. To do so, we set the K3S_KUBECONFIG_MODE
environment variable for the K3S daemonj to 644
:
Finally, I'll like to start k3s only on demand, therefore I'm disabling the autostart at boot time:
Now everything is in place and you should be able to connect to K3s:
To do so, copy the following parts from the /etc/rancher/k3s/k3s.yaml
to the ~/.kube/config
file - and make sure to change the name from default
to k3s-local
to avoid any future confusion:
Now you can test if everything still works with:
You should now also be able to connect to the local k3s using any other tool - for example K9S. Please note: If you are executing K9S using the Docker container, you also want to set the --net=host
flag so it actually can connect to the k3s running on the host (outside of Docker):
To make things easier to work with, you can add the local k3s connection to the default kubectl configuration file. This allows even third party tools such as to manage your local deployment without any further configuration needed.