TNS
VOXPOP
What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
0%
Super-fast S3 Express storage.
0%
New Graviton 4 processor instances.
0%
Emily Freeman leaving AWS.
0%
I don't use AWS, so none of this will affect me.
0%
Containers / Kubernetes

Portainer: How to add a Kubernetes Environment

This tutorial walks you through how to connect Portainer to a remote Kubernetes cluster, which will either need to be on the same LAN or accessible via an accessible FDQN.
Jun 12th, 2022 4:00am by
Featued image for: Portainer: How to add a Kubernetes Environment

Let’s talk Portainer again, shall we?

One of the brilliant aspects of Portainer container management system is that it allows you to add multiple environments, which can then be assigned to different teams. With that setup, you might have one team given access to the local environment for development, one team might have access to an Azure environment for deployment, and yet another team might have access to an Edge agent.

One other type of Environment you can add is for Kubernetes. With this environment added, you can then manage your Kubernetes, which makes it possible to manage:

  • Namespaces
  • Helm
  • Applications
  • ConfigMaps & Secrets
  • Cluster

When you create an application in a Portainer Kubernetes environment, you can do so from a manifest or using the Portainer form GUI (which is similar to adding a full stack or container deployment within a Docker environment).

For anyone who manages Kubernetes, and has been looking for a solid web-based GUI, adding a Kubernetes environment to Portainer is a great way to go.

The method I’m going to walk you through allows you to connect Portainer to a remote Kubernetes cluster, which will either need to be on the same LAN or accessible via an accessible FDQN.

Let me show you how this is done. I’m going to assume all you have up and running is a Linux server (I’ll demonstrate on Ubuntu Server 22.04, from start to finish).

How to Install Docker

The first thing we’re going to do is install Docker. Log into your Ubuntu Server instance and install the necessary dependencies with:


Next, add the official Docker GPG key with the command:


We can now add the Docker stable repository:


Finally, install Docker Engine with the following two commands:


Start and enable the Docker service with:


Next, you must add your user to the docker group with the command:


Make the system aware of the new group with:

How to Install kubectl and Minikube

We’re going to need both the kubectl command and Minikube installed. First, install kubectl with:


Install Kubectl with:


Next, we need to download the Minikube binary with:


Copy the binary to /usr/local/bin with:


Give the binary executable permission with:

How to Deploy Portainer

Next, we’ll deploy Portainer. First, create a volume (for persistent data) with:


Deploy Portainer with Docker, using the command:


Give the container a bit of time to spin up and then point your browser to http://SERVER:9443 (Where SERVER is the IP address of the hosting server). You will then need to create an account for Portainer and log in.

How to Add the Kubernetes Environment

We can now add our Kubernetes environment to Portainer. Click on Environments (in the left sidebar) and then (in the resulting page), click Add Environment (Figure 1).

Figure 1: I already have several environments configured in Portainer.

Figure 1: I already have several environments configured in Portainer.

In the next window (Figure 2), click the Agent tab.

Figure 2: The Environments creation page in Portainer.

Figure 2: The Environments creation page in Portainer.

In the resulting window (Figure 3), click Kubernetes via node port to reveal the command you must run on your Kubernetes host. That command is:


Once the command completes, go back to Portainer and fill out the information for the Environment. You’ll need to give the new environment a name (such as kube, k8s, minikube, etc.). Next, type the address of the Kubernetes server, as in:


 

Figure 3: Adding a new Kubernetes environment as an Agent.

Figure 3: Adding a new Kubernetes environment as an Agent.

If you want to assign the environment to a group, click the Group drop-down and select any group you’ve already created. Select any tags you’ve created and then click Add Environment. Click Add Environment and Portainer will connect to your Kubernetes cluster. Go back to the Portainer main window and you’ll see your new Kubernetes Environment listed (Figure 4).

Figure 4: Our new Kubernetes environment has been successfully added.

Figure 4: Our new Kubernetes environment has been successfully added.

Congratulations, you’ve added Kubernetes into the Portainer mix. Enjoy that added power and flexibility.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Docker.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.