k8s学习笔记——安装中常见错误1
1
1、节点状态NotReady
无论使用kubeadm init 初始化的节点,还是通过kubeadm join添加的节点,通过kubectl get node命令查看状态列都是NotReady状态。
第一步先为节点安装网络插件calico或者flannel,安装方法在上一节提到过,这里不做赘述。
安装网络插件的过程中发现,状态始终不变化,使用kubectl get pod -n kube-system命令查看,状态栏会出现 ImagePullBackOff 状态
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-66956989f4-94872 1/1 Running 0 16h
calico-node-46pcm 1/1 Running 1 56d
calico-node-dt6pv 1/1 Running 2 56d
calico-node-g7cpw 1/1 ImagePullBackOff 0 10h
calico-node-glzzp 0/1 Running 0 20d
calico-node-kz2l8 1/1 Running 0 3d10h
calico-node-ljr74 1/1 Running 2 90d
coredns-74ff55c5b-7q9tx 1/1 Running 0 16h
coredns-74ff55c5b-8tq4m 1/1 Running 0 16h
etcd-k8s70131 1/1 Running 0 2d23h
使用kubectl describe pod calico-node-g7cpw -n kube-system命令查看,会出现 “k8s.gcr.io/” 的字样,这里红色部分是pod的名,根据实际名填写。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreatePodSandBox 29s (x3 over 102s) kubelet Failed to create pod
sandbox: rpc error: code = Unknown desc = failed pulling image "k8s.gcr.io/pause:3.4.1":
Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while
waiting for connection (Client.Timeout exceeded while awaiting headers)
这是因为k8s通过kubeadm安装时需要通过docker拉取镜像,并且拉取下来的镜像标签必须是要和
kubeadm config images list
中的内容保持一致才能正确安装。
首先可以使用sudo docker images 命令看看本机有没有上述命令列表中的镜像,如果没有手动拉取。
这里注意一点,查看的节点位置。可以通过kubectl get pod -n kube-system -o wide 来看问题节点的ip,查看docker 镜像的节点位置是问题节点对应的ip主机。
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-66956989f4-94872 1/1 Running 0 16h 22.244.11.68 k8s70134 <none> <none>
calico-node-46pcm 1/1 Running 1 56d 10.12.70.133 k8s70133 <none> <none>
calico-node-dt6pv 1/1 ImagePullBackOff 2 56d 10.12.70.132 k8s70132 <none> <none>
第二步,手动拉取镜像
通过kubeadm config images list命令查看,需要拉取如下镜像
k8s.gcr.io/kube-apiserver:v1.21.2
k8s.gcr.io/kube-controller-manager:v1.21.2
k8s.gcr.io/kube-scheduler:v1.21.2
k8s.gcr.io/kube-proxy:v1.21.2
k8s.gcr.io/pause:3.4.1
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns/coredns:v1.8.0
因为k8s.gcr.io镜像库在国内需要翻墙,所以普通下载无法成功完成,可以更改一下下载的镜像库地址为国内地址,下载后将标签打回和kubeadm config一致的方法解决。
vim pullk8s.sh
for i in `kubeadm config images list`; do
imageName=${i#k8s.gcr.io/}
docker pull registry.aliyuncs.com/google_containers/$imageName
docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.aliyuncs.com/google_containers/$imageName
done;
此时查看docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
haproxy latest b68c771805b9 5 weeks ago 95.3MB
haproxy <none> 058875cd29c9 2 months ago 93.8MB
haproxy <none> 41c279cc8186 3 months ago 93.7MB
traefik latest 04ba4339d48a 3 months ago 95.2MB
calico/node v3.17.3 a45c42ebe880 4 months ago 165MB
calico/pod2daemon-flexvol v3.17.3 53f21afd77e8 4 months ago 21.7MB
calico/cni v3.17.3 32eddea2c8b4 4 months ago 128MB
k8s.gcr.io/kube-proxy v1.20.4 c29e6c583067 4 months ago 118MB
k8s.gcr.io/kube-controller-manager v1.20.4 0a41a1414c53 4 months ago 116MB
k8s.gcr.io/kube-apiserver v1.20.4 ae5eb22e4a9d 4 months ago 122MB
k8s.gcr.io/kube-scheduler v1.20.4 5f8cb769bd73 4 months ago 47.3MB
haproxy <none> 112ff8b8991a 4 months ago 94.3MB
k8s.gcr.io/etcd 3.4.13-0 0369cf4303ff 9 months ago 253MB
k8s.gcr.io/coredns 1.7.0 bfe3a36ebd25 12 months ago 45.2MB
osixia/keepalived stable d04966a100a7 15 months ago 72.9MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 16 months ago 683kB
这样等待一会后,在使用kubectl get pod -n kube-system查看状态都是Running就说明安装正常了。
更多推荐
所有评论(0)