How to Setup K3s Kubernetes with Portainer Without Docker

Posted April 13, 2024
How to Setup K3s Kubernetes with Portainer Without Docker

K3s is a lightweight Kubernetes distribution for your clusters. K3s if fully packaged to manage single node cluster and multi-cluster if you ever need one. Once to manage tour clusters, use Traefik or Rancher. However, tools like Portainer work perfectly and can manage Kubernetes like K3s on all levels.

In this guide, you will learn the ins and outs of setting up a K3s Kubernetes cluster with Portainer. You will do this without Docker. Portainer will give GUI to manage K3s containers. You will learn the following:

  • How to install K3s without Docker.
  • The steps of installing Portainer with K3s.
  • How to set up Portainer to manage K3s environments.
  • Adding k3s clusters and other management procedures to Portainer
  • How to create Multi k3s clusters (add worker nodes), Configure them with Portainer and manage them using the Portainer GUI.

Ready? Now dive in and set up K3s Kubernetes with Portainer GUI like a Pro.

Requisites to Installing K3s with Portainer

This K3s with Portainer tour is a step-by-step tutorial, ensure:

  • You have the right machine such as Debian, Ubuntu, or Raspberry.

Related: Install Single Node K3s on Ubuntu

  • Have some basics of working with K3s and Portainer.

Related: Install Docker and Portainer on Ubuntu

Installing K3s Without Docker

Before getting the Portainer ready, make sure you install your K3s cluster on as master Node as follows:

  • Use curl to install K3s:
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644

# Or

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" K3S_KUBECONFIG_MODE="644" sh -s -

This way:

  1. curl -sfL https://get.k3s.io gets the K3s installation script.
  2. INSTALL_K3S_EXEC="server" instructs the K3s installer to install K3s in server mode.
  3. K3S_KUBECONFIG_MODE="644" sets kubeconfig file permissions to 644.

Setup K3s Kubernetes with Portainer Without Docker

If you want to Install K3s without Traefik, use the following command:

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable=traefik" K3S_KUBECONFIG_MODE="644" sh -s -

Once installed, make sure K3s is up and running:

sudo systemctl status k3s

Setup K3s Kubernetes with Portainer Without Docker

Go further and make sure your K3s master Node is ready:

kubectl get nodes

Setup K3s Kubernetes with Portainer Without Docker

Related: Solving unable to read etc rancher k3s k3s yaml K3S Error

If Setting Up K3s and Portainer with Worker Nodes

If you don’t want to use a single-node cluster, you will create a worker node. In this case:

  • Get the token to connect worker nodes to the master node:
sudo cat /var/lib/rancher/k3s/server/node-token

Setup K3s Kubernetes with Portainer Without Docker

curl -sfL https://get.k3s.io | K3S_URL=https://master_node_ip:6443 K3S_TOKEN=master_node_token sh -

For example:

curl -sfL https://get.k3s.io | K3S_URL=https://3.215.127.246:6443 K3S_TOKEN=K106eb1c5f472471311abdf3207facc040c56a7326b0af76768a5a52bf64d466fb6::server:b48408931f330280ca524bc6af94198a sh -

Now, go over to the master and check if the worker node has been registered and ready, besides the master node:

kubectl get nodes

You should have a new node that should be ready:

Setup K3s Kubernetes with Portainer Without Docker

Installing Portainer Via K3s

It’s time to get Portainer ready. Here, you will run Portainer within your master node. In this case, you will use K3s and leverage the preinstall Portainer Kubernetes configuration.

Go ahead and run the following command to get the Portainer.yml file and apply the manifest to K3s:

sudo kubectl apply -n portainer -f https://raw.githubusercontent.com/portainer/k8s/master/deploy/manifests/portainer/portainer.yaml

Setup K3s Kubernetes with Portainer Without Docker

K3s will deploy Portainer and its container will be running as such:

kubectl get pods -A -o wide

Setup K3s Kubernetes with Portainer Without Docker

Exposing Portainer with K3s

Portainer is now deployed and ready to use K3s. Now you must make sure the Portainer Deployment and Service are okay using the following commands:

kubectl get deployment -n portainer
kubectl get svc -n portainer

Setup K3s Kubernetes with Portainer Without Docker

You will Note that K3s is running Portainer as a Nodeport, In this case, Portainer port 9000 is exposed through Nodeport 30777.

This means to access Portainer you will use:

http://master_node_ip:30777

Once you open that on the web you should get Portainer to create a new user as such:

Setup K3s Kubernetes with Portainer Without Docker

However, you might note the following result:

Setup K3s Kubernetes with Portainer Without Docker

You have done nothing wrong here. All you need is to restart your Portainer deployment with the following command:

kubectl rollout restart deployment -n portainer

Now go ahead and access Portainer, create a new user, and have the following UI ready:

Setup K3s Kubernetes with Portainer Without Docker

Configuring K3s with Portainer

Click the home button and your Kubernetes k3s ready on your local Portainer:

Setup K3s Kubernetes with Portainer Without Docker

Hit Live connect and K3s should be ready on your Portainer as such:

Setup K3s Kubernetes with Portainer Without Docker

You can even launch a shell to your K3s cluster through Portainer as such:

Setup K3s Kubernetes with Portainer Without Docker

Up to this point, you can also manage any K3s resources using the Portainer GUI.

How to Delete Portainer from K3s

If you now optimally want to remove Portainer from K3s, you will need to delete the deployed Portainer resources.

The following single command will remove Portainer on K3s:

kubectl delete deployments.apps/portainer -n portainer &&
kubectl delete service portainer -n portainer &&
kubectl delete serviceaccount -n portainer portainer-sa-clusteradmin &&
kubectl delete pvc portainer -n portainer &&
kubectl delete clusterrolebinding portainer &&
kubectl delete namespace portainer &&
rm -f portainer.yaml

Setup K3s Kubernetes with Portainer Without Docker

  1. kubectl delete deployments.apps/portainer -n portainer && to deletes portainer deployment

  2. kubectl delete service portainer -n portainer && deletes portainer service named

  3. kubectl delete serviceaccount -n portainer portainer-sa-clusteradmin && remove the service account.

  4. kubectl delete pvc portainer -n portainer && to get rid of portainer persistent volume claim (PVC).

  5. kubectl delete clusterrolebinding portainer &&: Deletes the cluster role binding named “portainer”.

  6. kubectl delete namespace portainer && to remove the namespace portainer.

  7. rm -f portainer.yaml deletes portainer.yaml file.

Conclusion

This guide helped you create and set up a Portainer GUI to manage Portainer. You’ve learned:

  • How to install K3s without Docker.
  • The steps of installing Portainer with K3s.
  • How to set up Portainer to manage K3s environments.
  • Adding k3s clusters and other management procedures to Portainer.
  • How to create Multi k3s clusters (add worker nodes), Configure them with Portainer and manage them using the Portainer GUI.
How to Setup K3s Kubernetes with Portainer Without Docker

Written By:

Joseph Chege