目录
kubelet和docker的Cgroup Driver不同导致kubelet开启失败
集群环境
IP 节点 所需部件 192.168.116.23 master docker-ce、kubeadm、kubelet、kubectl 192.168.116.24 node1 docker-ce、kubeadm、kubelet、kubectl 192.168.116.25 node2 docker-ce、kubeadm、kubelet、kubectl
systemctl disable --now firewalld.service
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
- free -m
- #查看swap情况
sed -ri 's/.*swap.*/#&/' /etc/fstab
重启后生效
- cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
- br_netfilter
- EOF
- cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
- net.bridge.bridge-nf-call-ip6tables = 1
- net.bridge.bridge-nf-call-iptables = 1
- EOF
sysctl --system
添加要作为master节点的服务器IP的域名对应关系
echo "192.168.116.23 cluster-endpoint">> /etc/hosts
具体请参考Docker概念与基础操作
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && yum install -y docker-ce
systemctl enable --now docker.service
docker --version
添加yum源
- cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
- [kubernetes]
- name=Kubernetes
- baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
- enabled=1
- gpgcheck=0
- repo_gpgcheck=0
- gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
- http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
- exclude=kubelet kubeadm kubectl
- EOF
进行下载,注意版本一致问题
sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9
sudo systemctl enable --now kubelet
kube-apiserver:v1.20.9
kube-proxy:v1.20.9
kube-controller-manager:v1.20.9
kube-scheduler:v1.20.9
coredns:1.7.0
etcd:3.4.13-0
pause:3.2
使用脚本完成镜像拉取
- sudo tee ./images.sh <<-'EOF'
- #!/bin/bash
- images=(
- kube-apiserver:v1.20.9
- kube-proxy:v1.20.9
- kube-controller-manager:v1.20.9
- kube-scheduler:v1.20.9
- coredns:1.7.0
- etcd:3.4.13-0
- pause:3.2
- )
- for imageName in ${images[@]} ; do
- docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName
- done
- EOF
执行脚本
chmod +x ./images.sh && ./images.sh
curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
kubectl apply -f calico.yaml
- kubeadm init \
- --apiserver-advertise-address=192.168.116.23 \
- --control-plane-endpoint=cluster-endpoint \
- --image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
- --kubernetes-version v1.20.9 \
- --service-cidr=10.96.0.0/16 \
- --pod-network-cidr=192.168.0.0/16
初始化后成功注意以下信息,上面的命令在master执行,下面的在要加入集群的node服务器上执行。
- [kubelet-check] Initial timeout of 40s passed.
- error execution phase upload-config/kubelet:
- Error writing Crisocket information for the control-plane node: timed out waiting for the condition
swapoff -a && kubeadm reset && systemctl daemon-reload && systemctl restart kubelet && iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
然后重新进行初始化
在node节点服务器输入master服务器上初始化成功后加入集群的命令
- failure loading certificate for CA: couldn't load the certificate file
- /etc/kubernetes/pki/ca.crt: open /etc/kubernetes/pki/ca.crt:
- no such file or directory
疑似缺失证书文件
实际上发现,是在复制执行命令时带上了--control-plane,去掉后表示为以node服务器加入集群(摊手)
在master节点使用kubectl命令行工具进行查看目前集群情况
kubectl命令格式:
kubectl [command] [TYPE] [NAME] [flags]
kubectl get nodes
kubectl get pod -A
kubectl get cs
这里很明显两个大大的“Unhealthy”不健康写在面前,需要我们去修改一下端口号来解决
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
vim /etc/kubernetes/manifest/kube-scheduler.yaml
稍微等待一会,再次查看,这回都是healthy了
查看Cgroup Driver
docker info | grep Driver
systemctl show --property=Environment kubelet | cat
- /etc/docker/daemon.json
-
- {
- "exec-opts": ["native.cgroupdriver=systemd"]
- }
- vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
-
- –-cgroup-driver=systemd
- #添加或修改
- systemctl daemon-reload
-
- systemctl restart docker
-
- systemctl restart kubelet