kind搭建k8s集群用于测试

安装kind 需要先安装go kind基于go开发

#修改go源加快下载速度
go env -w GOPROXY=https://goproxy.cn,direct
#直接下载安装kind最新版本
go install sigs.k8s.io/kind@latest
#进入GOPATH目录找到bin目录下kind执行程序 移动到环境变量里
mv ./kind /usr/local/bin/
#提前下载k8s镜像
docker pull kindest/node:v1.22.0
#启动
kind create cluster --image=kindest/node:v1.22.0 --name=dev
#查看
kind get clusters
#通过名字删除集群
kind delete cluster --name=dev

出现的问题及解决办法:
如果报如下错误:

[root@192 ~]# kind create cluster --image=kindest/node:v1.22.0 --name=dev
Creating cluster "dev" ...
 ✓ Ensuring node image (kindest/node:v1.22.0) 
 ✗ Preparing nodes   
Deleted nodes: ["dev-control-plane"]
ERROR: failed to create cluster: command "docker run --name dev-control-plane --hostname dev-control-plane --label io.x-k8s.kind.role=control-plane --privileged --security-opt seccomp=unconfined --security-opt apparmor=unconfined --tmpfs /tmp --tmpfs /run --volume /var --volume /lib/modules:/lib/modules:ro -e KIND_EXPERIMENTAL_CONTAINERD_SNAPSHOTTER --detach --tty --label io.x-k8s.kind.cluster=dev --net kind --restart=on-failure:1 --init=false --cgroupns=private --volume /dev/mapper:/dev/mapper --publish=127.0.0.1:33059:6443/TCP -e KUBECONFIG=/etc/kubernetes/admin.conf kindest/node:v1.22.0" failed with error: exit status 125
Command Output: WARNING: Your kernel does not support cgroup namespaces.  Cgroup namespace setting discarded.
a416609b76ef8e1bf4fdac66c159a0f1396841464aec2c8cc6e667fc83be83fe
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: cgroup namespaces aren't enabled in the kernel: unknown.

原因是内核不支持cgroup 解决办法: 升级内核
注意:升级前做好备份

#1 更新系统,确保所有安装的包都是最新的
sudo yum update
#2安装 elrepo 仓库,该仓库提供了最新的稳定内核
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
#3 安装新的内核(例如,最新的稳定版本是 kernel-ml)
sudo yum --enablerepo=elrepo-kernel install kernel-ml -y
#4 更新GRUB引导菜单
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
#5 修改默认引导顺序,使新内核成为默认引导
sudo grub2-set-default 0
#6 重新启动系统,确认新内核成功安装并生效
sudo reboot

你可能感兴趣的:(kubernetes)