Launch a kubernetes cluster is the first step to learn it. As is well known, Kubernetes cluster is a complexity application. There are lots of components in kubernetes cluster, that makes the learning curve is steep. Lots of beginner are deterred from kubernetes due to the difficulty of creating a kubernetes cluster.
Even though kubeadm did all the heavy lifting in create a kubernetes cluster, it still hard to get started for the beginners.
If you are seeking a one-click deployment for creating a kubernetes cluster in the development & testing environments, you are getting the right place. In this article, I will go through how to create a kubernetes cluster quickly via Kind.
What is Kind?
kind(Kubernetes in Docker) is a tool for running local Kubernetes clusters
using Docker container “nodes”.
In short kind targets local clusters for testing purposes
. While not all testing can be performed without “real” clusters in “the cloud” with provider enabled CCMs, enough can that we want something that:
Prepare a machine wich install Docker Engine with 2 CPUs, 4GB RAM.
Kind
support useDocker
,podman
, ornerdctl
as the driver. In this article, I will use theDocker Engine
as the driver.
How to install Docerk Engine
in different operating system, please follow this tutorial -- Installing Docker, after the docker engine installed, you can keep going for next step.
Following the instruction with Install kubectl on Linux.
Following the instruction with Install kubectl on MacOS.
Following the instruction with Install kubectl on Windows.
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
# Check kind version
kind version
# For Intel Macs
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-darwin-amd64
# For M1 / ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-darwin-arm64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind
# Check kind version
kind version
curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.23.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe
By default, kind
will create a kubernetes cluster with a all-in-one node.
cerek@kind-k8s-cluster:~$ kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.30.0) 🖼
✓ 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
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
Check kubernetes cluster informaction.
cerek@kind-k8s-cluster:~$ kind get clusters
kind
cerek@kind-k8s-cluster:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 2m14s v1.30.0
cerek@kind-k8s-cluster:~$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
kind-control-plane Ready control-plane 2m21s v1.30.0 172.18.0.3 <none> Debian GNU/Linux 12 (bookworm) 5.10.0-30-amd64 containerd://1.7.15
Deploy a simple web service.
This is a example for the simple web service in yaml file.
cerek@kind-k8s-cluster:~$ cat deployment-web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-web
spec:
replicas: 3
selector:
matchLabels:
app: simple-web
env: testing
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: simple-web
env: testing
spec:
containers:
- name: web
image: nginx:1.21.6
ports:
- name: web-port
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: simple-web-service
labels:
app: sws
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: simple-web
env: testing
Apply the simple web service yaml config file to kubernetes, and check all the staff on it.
cerek@kind-k8s-cluster:~$ kubectl apply -f deployment-web.yaml
deployment.apps/simple-web created
service/simple-web-service created
cerek@kind-k8s-cluster:~$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
simple-web 3/3 3 0 15s
cerek@kind-k8s-cluster:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
simple-web-69f68c5fc-7r86p 1/1 Running 0 20s
simple-web-69f68c5fc-cv4xm 1/1 Running 0 20s
simple-web-69f68c5fc-v29tb 1/1 Running 0 20s
cerek@kind-k8s-cluster:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12m
simple-web-service ClusterIP 10.96.159.163 <none> 80/TCP 22s
Try to access the web service.
cerek@kind-k8s-cluster:~$ docker exec -it 981d5eaa9d2f curl -I 10.96.159.163
HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Sat, 20 Jul 2024 22:18:54 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
Command | Description |
---|---|
kind version | Prints the kind CLI version |
kind create cluster | Create Cluster |
kind delete cluster | Delete Cluster |
kind get clusters | List Clusters |
kind get kubeconfig | Get Kubeconfig |
kind load docker-image my-custom-image:latest | Load Docker Image |
Common Options | --name, --image, --config |
kind
(Kubernetes IN Docker) tool has provided valuable insights into simplifying Kubernetes cluster creation and management. Kind offers an accessible and efficient way to set up local Kubernetes clusters within Docker containers, which is ideal for development and testing purposes. Its ease of setup, resource efficiency make it a powerful tool for developers.
Overall, kind
stands out as a robust solution for creating Kubernetes clusters locally, offering a practical environment for experimentation and development without the overhead of cloud infrastructure. This experience has solidified my understanding of Kubernetes and prepared me for more advanced projects involving Kubernetes cluster management.