Kind是一个在本地跑k8s环境的工具,他使用Docker container作为k8s的节点。
Kind致力于测试k8s本身,但是如果用它来做搭建本地开发环境,或者用来做CICD也是很不错的。
Kind的安装过程十分的简单(推荐go 1.13及之后的版本):
root@nick-dev-vm01:~# GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0
然后查看一下帮助:
root@nick-dev-vm01:~# kind help
kind creates and manages local Kubernetes clusters using Docker container 'nodes'
Usage:
kind [command]
Available Commands:
build Build one of [node-image]
completion Output shell completion code for the specified shell (bash, zsh or fish)
create Creates one of [cluster]
delete Deletes one of [cluster]
export Exports one of [kubeconfig, logs]
get Gets one of [clusters, nodes, kubeconfig]
help Help about any command
load Loads images into nodes
version Prints the kind CLI version
Flags:
-h, --help help for kind
--loglevel string DEPRECATED: see -v instead
-q, --quiet silence all stderr output
-v, --verbosity int32 info log verbosity
Use "kind [command] --help" for more information about a command.
在查看一下创建集群的帮助:
root@nick-dev-vm01:~# kind help create
Creates one of local Kubernetes cluster (cluster)
Usage:
kind create [command]
Available Commands:
cluster Creates a local Kubernetes cluster
Flags:
-h, --help help for create
Global Flags:
--loglevel string DEPRECATED: see -v instead
-q, --quiet silence all stderr output
-v, --verbosity int32 info log verbosity
Use "kind create [command] --help" for more information about a command.
下面我们开始创建集群:
root@nick-dev-vm01:~# 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
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community
几乎只需要1分钟的时间,集群就创建好了。
查看刚刚创建好的集群:
root@nick-dev-vm01:~# kind get clusters
kind
我们来试一下kubectl(请确保已经正确安装kubectl):
root@nick-dev-vm01:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready master 12m v1.19.1
root@nick-dev-vm01:~# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-f9fd979d6-cmjls 1/1 Running 0 12m
kube-system coredns-f9fd979d6-s4lfm 1/1 Running 0 12m
kube-system etcd-kind-control-plane 1/1 Running 0 12m
kube-system kindnet-m2sk2 1/1 Running 0 12m
kube-system kube-apiserver-kind-control-plane 1/1 Running 0 12m
kube-system kube-controller-manager-kind-control-plane 1/1 Running 0 12m
kube-system kube-proxy-9tr4k 1/1 Running 0 12m
kube-system kube-scheduler-kind-control-plane 1/1 Running 0 12m
local-path-storage local-path-provisioner-78776bfc44-9g5qq 1/1 Running 0 12m
可以看到已经跑起来了。
现在尝试用helm来安装一下chart(请确保已经正确安装helm3):
root@nick-dev-vm01:~# helm3 repo add stable https://charts.helm.sh/stable
root@nick-dev-vm01:~# helm3 install stable/mysql --generate-name
查看一下,chart已经正确安装了:
root@nick-dev-vm01:~# helm3 list -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1610677591 default 1 2021-01-15 02:26:33.914710058 +0000 UTC deployed mysql-1.6.9 5.7.30
使用kubectl来检查:
root@nick-dev-vm01:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
mysql-1610677591-7fbf867c56-sz56f 0/1 Running 0 20s
Pod已经运行起来了。
你也可以删除集群,使用下面的命令:
root@nick-dev-vm01:~# kind delete cluster
Deleting cluster "kind" ...
最后放一张kind minikube的对比图:
本文暂时没有评论,来添加一个吧(●'◡'●)