Getting started with Portainer using Kind

Getting started with Portainer using Kind

Setup a multi-node k8s cluster in your local system using Kind and manage it using Portainer.io.

Pre-reqs

  • Should know basics of k8s

Background

Have you ever wanted a simple Kubernetes cluster to try things out ? Or just to get familiar with kubernetes components, commands and other stuff ? Basically, have you ever wanted a Kubernetes Playground ?

There are many platforms that offer you kubernetes clusters to play with. For example: Katacoda, Play with Kubernetes, Minkube etc. Or else you can go with GKE(google), EKS(amazon) etc.

But as far as I found, there are limitations with those options. Either these clusters/environments are temporary(Katacoda, Play with Kubernetes etc) or you get only a single node cluster(Minukube) or you will have to pay for what you consume(GKE, EKS etc).

What if, we can set up a highly available kuberenetes cluster locally for our development and testing purposes ? Which is permanent and also it doesn't cost you a single penny. Sounds great ? Furthermore , if the cluster setup process is simple and straight forward ? If you think that is awesome, then this article is for you.

This can be used as a playground for practicing CKA,CKAD and CKS certifications and also can give you close to real world production experience.

Introduction to Kind?

  • What is Kind (Kind vs Minikube)

    kind is a tool for running local Kubernetes clusters using Docker container as “nodes”. kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

  • Install Kind

    Steps:
    • Install Docker

      You must have docker installed and running. You can select and follow the documentation as per your OS.
  • Install kubectl

    Installing kubectl on your local machine will let you access the cluster from your local machine. Follow this documentation to install and setup kubectl.
  • Install Kind

    You can follow the below documentation or run below commands that I have mentioned, here I am using Ubuntu distro on WSL2.

    On Linux:

    curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
    chmod +x ./kind
    sudo mv ./kind /usr/local/bin/kind
    

    You can also have a look at Kind Installation Documentation To check if Kind is successfully installed in you system, run

    kind
    

    You should see some info about Kind like this image.png

Kind Project GitHub:

Now the main question "Why use Kind?"(Kind vs minikube)

minikube is project started and managed by k8s community directly. To know more details about minikube visit: minikube docs

But the strange thing is that the same k8s community built another project called Kind with seemingly same objectives i.e. for running k8s cluster locally, but you may be thinking now "why build another project with almost the same objective, there must be something that Kind(a relatively newer Project) can do which minikube can not ", to answer that we'll look into some features that Kind offers.

  • When you run command in your Linux distro it by default creates a single node cluster.

    kind create cluster --name my-cluster
    

    image.png To see you cluster details run

    kubectl get nodes
    

    image.png And to confirm that this cluster is running as a Docker container, run this command

    docker ps
    

    image.png It'll show you the running container with "kindest/node" image

  • It can load the docker-images from the host or archive into nodes. image.png

But these are not an advantage over minikube as minikube also can perform same things, then what is the advantage of Kind over minikube, we'll see it now, remember you created a single node cluster in the first point of its features? Keep that cluster running and try to create another cluster with different name this time

kind create cluster --name another-cluster

image.png And now you'll notice that it lets you create another cluster along with the previous cluster already running which is not at all possible with minikube or even with docker desktop. To see both of your clusters just run again

docker ps

image.png

It'll show you 2 containers running with names that you provided. Amazing isn't it!! Now to delete these clusters just run the commands one by one with each cluster's name

kind delete cluster --name my-cluster
kind delete cluster --name another-cluster

image.png It'll very quickly delete the two clusters because it just had to delete the docker containers, so now if you check with

docker ps

image.png you won't see any container running

There is another big advantage of Kind over minikube, lets see

I want to change the cluster name and also I want to have 1 master node and 2 worker nodes. Lets see how we can achieve that.

Create kind config file

cat > kind-config.yaml <<EOF
# three node (1 control plane and 2 workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF

Create cluster

kind create cluster --name k8s-playground --config kind-config.yaml

image.png Now the cluster is ready and you can use kubectl commands to work on the cluster. You can run kubectl commands from your local machine.

kubectl get nodes

image.png

docker ps

image.png

Introduction to Portainer

Now that we have our multi node cluster set up already lets see what Portainer is.

what is Portainer?

Portainer is an open source toolset that allows you to easily build and manage containers in Docker, Docker Swarm, Kubernetes and Azure ACI.

Portainer hides the complexity of managing containers behind an easy-to-use UI. By removing the need to use the CLI, write YAML or understand manifests, Portainer makes deploying apps and troubleshooting problems so easy that anyone can do it.

Portainer architecture

Portainer consists of two elements: the Portainer Server and the Portainer Agent. Both run as lightweight containers on your existing containerized infrastructure. The Portainer Agent should be deployed to each node in your cluster and configured to report back to the Portainer Server container.

A single Portainer Server will accept connections from any number of Portainer Agents, providing the ability to manage multiple clusters from one centralized interface. To do this, the Portainer Server container requires data persistence. The Portainer Agents are stateless, with data being shipped back to the Portainer Server container.

portainer-architecture-detailed.png

To see more details on

Portainer Github Repo

Install Portainer

We are going to deploy Portainer CE within our Kubernetes cluster using their helm charts by running following commands

Note: Helm should be installed before running the commands, to install helm see this documentation

helm repo add portainer https://portainer.github.io/k8s/

image.png

helm repo update

image.png

Once the update completes, you're ready to begin the installation. Expose your portainer port via NodePort using

helm install --create-namespace -n portainer portainer portainer/portainer

image.png

To check if you Portainer services are running, run

kubectl get all -n portainer

image.png

Check the created namespace with helm command

helm list --all-namespaces

image.png

After checking everything port-forward your request to port 30777

kubectl port-forward -n portainer svc/portainer 30777:9000

image.png

Open your preferred browser and go to localhost:30777, you should see a page like this image.png

setup your account on Portainer and you should be inside Portainer Dashboard image.png To see your cluster, click on "Home" form top left corner

image.png Click on your cluster which you see on Home dashboard

image.png

You can see your nodes in cluster section

image.png

You can add a team image.png Add a new User to a team you just created image.png

Inside teams dashboard you can see your user added as a member of that team image.png And there are many more feature that you can explore in Portainer CE edition image.png

So, This is it about Portainer in this blog, Topics we covered in this blog

  • what is kind
  • why use kind (kind vs minikube)
  • Get started with kind
  • What is Portainer
  • Get started with Portainer
  • Manage your k8s cluster with Portainer

Thanks for reading the blog, hope you learned something from this, if you did then do share it on twitter & linkedin and tag me at:

If you have any doubt or feedbacks, feel free to drop it in the comment section. And don't forget to react on this blog.

References

Thanks Again for reading this blog, stay tuned for more blog on different cloud technologies!!