Want to learn Kubernetes but don’t know how to create a local cluster? No worries, I will explain how to create a multi-node Kubernetes cluster locally on your own machine. No need to buy any cloud provider service and spend a penny for just learning or testing purposes. Use Kind to create Kubernetes cluster on top of Docker containers.
What is a Cluster?
As the name suggests a Cluster is a group of inter linked computer systems aimed to host an online application and its required softwares that seamlessly serve the application over internet without downtime. A cluster can be made up off real systems or it could be virtual system having same computing capabilities. Individual system could have different operating systems running inside as per the software requirements. In case of micro service architecture these days we largely see the use of cloud cluster based deployments.
Why use a Cluster setup for your online business application?
- High availability
- Zero or Less Downtime
- Easy Horizontal Expansion
- Helps in DevOps
- Easy for Microservice architecture
The Problem With The Containerized Application
Kubernetes is a container orchestration tool that helps you manage your containers smoothly. You might be thinking about what to manage in a containerized application if you are using Docker for your development process. Usually, what happens in a development environment, we create a single container for each of our services required for the application. And in the development environment, the containers never go down as a few users access the application, and hence the load on the server is manageable.
But this is not the same for a production environment. A production environment application is accessed by millions of users and hence the load on the server is high. So there are chances for server crashes. So we somehow need to run multiple duplicate containers for all or some of our services in the application. Not only just creating and running multiple containers per service is sufficient to handle the production server load. We somehow need to ensure that if any of our container services goes down we have to turn it up again. We need to check the health of our containers periodically. Also, we need to distribute traffic equally on each container.
Using Kubernetes To Manage Container
Doing all this stuff manually is quite difficult. So we need some kind of automated tool that will do all these tasks for us. We can use Kubernetes for this purpose. But before applying some new tools on a live production server we have to learn that tool properly and test our application behavior on it locally. Usually, Kubernetes clusters are managed by cloud service providers for production environment usage. But for local development/testing, we have to use some kind of tool that can provide a similar cluster on our local machine.
Kind as a multi-node Kubernetes Cluster
Kind is one such tool, we can use it for creating a multi-node cluster on local machines. That helps us learn Kubernetes for free. Kind works on top of containers, with no need for physical machines or virtual machines. Just start your docker engine and you are good to go with Kind Cluster.
To create a Kind Kubernetes cluster run the below command after starting your Docker engine.
kind create cluster --config <path to kind cluster config file>
Next, create a Kind cluster configuration file named kind_cluster_config.yaml and put the following code in it. This configuration will create 3 nodes 1 is the master node/control-plane and 2 worker nodes. This cluster is also ingress-ready.
- role: control-plane
- containerPort: 80
- containerPort: 443
- role: worker
- role: worker
For more information on Kubernetes with Kind please visit https://kind.sigs.k8s.io/