• About WordPress
    • WordPress.org
    • Documentation
    • Support
    • Feedback
  • Log In
  • Register
  • Home
  • About Us
  • Blog
  • Courses
  • Contact Us

Have any question?

101daysofdevops@gmail.com
RegisterLogin
101DaysofDevops
  • Home
  • About Us
  • Blog
  • Courses
  • Contact Us

Blog

  • Home
  • Blog
  • Blog
  • Kubernetes in Docker(kind)

Kubernetes in Docker(kind)

  • Posted by lakhera2020
  • Date February 2, 2021
  • Comments 0 comment

Reference: https://kind.sigs.k8s.io/

As per official documentation

kind is a tool for running local Kubernetes clusters using Docker container โ€œnodesโ€. kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

Prerequisites

To install kind, you need to meet the following prerequisites

  • Go need to be installed
  • Docker should be up and running

Installation

To download and install kind on Linux based system.

curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.9.0/kind-$(uname)-amd64"
chmod +x ./kind
mv ./kind /usr/local/bin/kind
  • Once the kind is installed, you can verify its version using.
kind version                                                              
kind v0.9.0 go1.15.2 linux/amd64

Create your first Kubernetes cluster

The easiest way to create your one node Kubernetes cluster is by executing the below command. Behind the scene kind is going to pull the docker image(kindest/node:v1.19.1) to setup the cluster for you.

kind create cluster                                                       
Creating cluster "kind" ...
โœ“ Ensuring node image (kindest/node:v1.19.1) ๐Ÿ–ผ
โœ“ Preparing nodes ๐Ÿ“ฆ
โœ“ Writing configuration ๐Ÿ“œ
โœ“ Starting control-plane ๐Ÿ•น๏ธ
โœ“ Installing CNI ๐Ÿ”Œ
โœ“ Installing StorageClass ๐Ÿ’พ
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! ๐Ÿ˜Š
  • Once this done we have kube config ready for us
ls -l ~/.kube/config
-rw-------  1 plakhera  staff  5608 Oct  9 09:23 /Users/plakhera/.kube/config
  • You can verify the image it has downloaded
docker image ls
REPOSITORY     TAG       IMAGE ID       CREATED        SIZE
kindest/node   <none>    d372b674475a   4 months ago   1.1GB
  • You can even verify the docker container it’s running, by executing the below command
> docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED      STATUS      PORTS                       NAMES
4bf12cd3dc13   kindest/node:v1.21.1   "/usr/local/bin/entrโ€ฆ"   4 days ago   Up 2 days   127.0.0.1:49713->6443/tcp   my-kind-cluster-control-plane
9db63205451e   kindest/node:v1.21.1   "/usr/local/bin/entrโ€ฆ"   4 days ago   Up 2 days                               my-kind-cluster-worker
c92dd6d3c367   kindest/node:v1.21.1   "/usr/local/bin/entrโ€ฆ"   4 days ago   Up 2 days                               my-kind-cluster-worker2
  • By default kind will switch to the context of the cluster you have created but if you want to switch to the particular context
kubectl config use-context kind-kind
Kubernetes control plane is running at https://127.0.0.1:41917
KubeDNS is running at https://127.0.0.1:41917/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
  • kind has created a one node cluster for you.
kubectl get nodes                       
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready master 44s v1.19.1
  • In case if you donโ€™t passโ€Šโ€”โ€Šname argument, kind will create a cluster with default name set to kind.
  • To verify the cluster created by kind
kind get clusters        
kind
  • To delete the above cluster
kind delete clusters kind                   
Deleted clusters: ["kind"]
kind get clusters        
No kind clusters found.
  • To delete the above cluster
kind delete clusters kind                   
Deleted clusters: ["kind"]
kind get clusters        
No kind clusters found.
  • Now the above cluster is created by fetching the latest image of kind from dockerhub, if you want to install the specific version
kind create cluster --name my-kind-cluster --image kindest/node:v1.19.7
Creating cluster "my-kind-cluster" ...
โœ“ Ensuring node image (kindest/node:v1.19.7) ๐Ÿ–ผ
โœ“ Preparing nodes ๐Ÿ“ฆ
โœ“ Writing configuration ๐Ÿ“œ
โœ“ Starting control-plane ๐Ÿ•น๏ธ
โœ“ Installing CNI ๐Ÿ”Œ
โœ“ Installing StorageClass ๐Ÿ’พ
Set kubectl context to "kind-my-kind-cluster"
You can now use your cluster with:
kubectl cluster-info --context kind-my-kind-cluster
Have a nice day! ๐Ÿ‘‹

To list all the supported version 

  • We have created a one-node cluster(both control-plane(master) and worker in the same node). A multi-node cluster can be created by passing a simple configuration file.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
  • The above configuration file will create one control-plane and two worker nodes.
  • To create a cluster using the above configuration, please pass โ€” config to the configuration.
kind create cluster --name my-kind-cluster --config my-example-config.yaml 
Creating cluster "my-kind-cluster" ...
โœ“ Ensuring node image (kindest/node:v1.19.1) ๐Ÿ–ผ
โœ“ Preparing nodes ๐Ÿ“ฆ ๐Ÿ“ฆ ๐Ÿ“ฆ
โœ“ Writing configuration ๐Ÿ“œ
โœ“ Starting control-plane ๐Ÿ•น๏ธ
โœ“ Installing CNI ๐Ÿ”Œ
โœ“ Installing StorageClass ๐Ÿ’พ
โœ“ Joining worker nodes ๐Ÿšœ
Set kubectl context to "kind-my-kind-cluster"
You can now use your cluster with:
kubectl cluster-info --context kind-my-kind-cluster
Thanks for using kind! ๐Ÿ˜Š
  • As you can see your three node cluster is up and running
kubectl get nodes                                  
NAME STATUS ROLES AGE VERSION
my-kind-cluster-control-plane Ready master 2m17s v1.19.1
my-kind-cluster-worker Ready <none> 101s v1.19.1
my-kind-cluster-worker2 Ready <none> 101s v1.19.1
  • My favorite feature is that if you want to create a multi-node cluster with multiple control planes (master) and worker nodes, it is easily doable via bind. You need to modify the definition by adding more than one control-plane to the definition.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
  • Nothing change on the command end and you need to run the same command
kind create cluster --name my-kind-cluster --config my-example-config.yaml
Creating cluster "my-kind-cluster" ...
 โœ“ Ensuring node image (kindest/node:v1.19.1) ๐Ÿ–ผ
 โœ“ Preparing nodes ๐Ÿ“ฆ ๐Ÿ“ฆ ๐Ÿ“ฆ ๐Ÿ“ฆ ๐Ÿ“ฆ  
 โœ“ Configuring the external load balancer โš–๏ธ 
 โœ“ Writing configuration ๐Ÿ“œ 
 โœ“ Starting control-plane ๐Ÿ•น๏ธ 
 โœ“ Installing CNI ๐Ÿ”Œ 
 โœ“ Installing StorageClass ๐Ÿ’พ 
 โœ“ Joining more control-plane nodes ๐ŸŽฎ 
 โœ“ Joining worker nodes ๐Ÿšœ 
Set kubectl context to "kind-my-kind-cluster"
You can now use your cluster with:
kubectl cluster-info --context kind-my-kind-cluster
Thanks for using kind! ๐Ÿ˜Š
  • Yay your multi-node cluster is up and running
kubectl get nodes
NAME STATUS ROLES AGE VERSION
my-kind-cluster-control-plane Ready master 3m4s v1.19.1
my-kind-cluster-control-plane2 Ready master 2m35s v1.19.1
my-kind-cluster-worker Ready <none> 97s v1.19.1
my-kind-cluster-worker2 Ready <none> 97s v1.19.1
my-kind-cluster-worker3 Ready <none> 97s v1.19.1
  • As you can see along with multi-node cluster it’s also setup load balancer for you. You can verify load balancer configuration by
> docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED          STATUS         PORTS                       NAMES
be68932ea592   kindest/haproxy:v20200708-548e36db   "/docker-entrypoint.โ€ฆ"   2 minutes ago    Up 2 minutes   127.0.0.1:51857->6443/tcp   multi-node-cluster-external-load-balancer


> docker exec -it be68932ea592 sh
/ # ps -ef
PID   USER     TIME  COMMAND
    1 root      0:00 haproxy -sf 7 -W -db -f /usr/local/etc/haproxy/haproxy.cfg
   33 root      0:00 haproxy -sf 7 -W -db -f /usr/local/etc/haproxy/haproxy.cfg
   37 root      0:00 sh
   45 root      0:00 ps -ef


/ # cat /usr/local/etc/haproxy/haproxy.cfg
# generated by kind
global
  log /dev/log local0
  log /dev/log local1 notice
  daemon

resolvers docker
  nameserver dns 127.0.0.11:53

defaults
  log global
  mode tcp
  option dontlognull
  # TODO: tune these
  timeout connect 5000
  timeout client 50000
  timeout server 50000
  # allow to boot despite dns don't resolve backends
  default-server init-addr none

frontend control-plane
  bind *:6443
  
  default_backend kube-apiservers

backend kube-apiservers
  option httpchk GET /healthz
  # TODO: we should be verifying (!)
  
  server multi-node-cluster-control-plane multi-node-cluster-control-plane:6443 check check-ssl verify none resolvers docker resolve-prefer ipv4
  server multi-node-cluster-control-plane2 multi-node-cluster-control-plane2:6443 check check-ssl verify none resolvers docker resolve-prefer ipv4

Wrapping Up

Kind is super powerful, and in this blog, I barely scratch the surface. If you donโ€™t want to spend hours building Kubernetes cluster or $$$ in building cluster in the cloud, kind is a tool for you. 

Tag:devops, kind, kubernetes

  • Share:
author avatar
lakhera2020

Previous post

Kubernetes Terminal Dashboard k9s
February 2, 2021

Next post

MetalLB Load Balancer for Bare Metal Kubernetes
February 3, 2021

You may also like

Am I reading the iostat command output correctly?
25 April, 2022

Iostat command came from the same sysstat family package # rpm -qf `which iostat` sysstat-11.7.3-6.el8.x86_64 It mainly read data from /proc/diskstats # cat /proc/diskstats 259 0 nvme1n1 147 0 6536 …

Debugging Performance Issue usingย SAR
21 April, 2022

What is SAR? SAR is a utility used to collect and report system activity. It collects data relating to most core system functions and writes those metrics to binary data …

4 common Kubernetes Pods Error and Debugging
20 April, 2022

Why do Kubernetes Pods fail? The two most common reasons for Kubernetes pod failure is The container inside the pod doesnโ€™t start, which we also call a startup failure. The …

Leave A Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Am I reading the iostat command output correctly?
  • Debugging Performance Issue usingย SAR
  • 4 common Kubernetes Pods Error and Debugging
  • My road to Gremlin Chaos Engineering Practitioner Certificate
  • My road to Certified Kubernetes Security Specialist (CKS)

Recent Comments

  • lakhera2020 on Debugging Performance Issue usingย SAR
  • Anonymous on Debugging Performance Issue usingย SAR
  • Pety on Day 2 – MetalLB Load Balancer for Bare Metal Kubernetes
  • akashambasta on Day 1 – AWS IAM User
  • rd on 100 Days of AWS

 

101daysofdevops@gmail.com

  • Home
  • About Us
  • Courses
  • Blog

ยฉ 101daysofdevops. All rights reserved.

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now