问题场景:
在安装完毕K8S之后,执行 kubectl get ns 报错:
[root@master ~]# kubectl get pods
E0501 08:34:55.770030 11268 memcache.go:265] couldn't get current server API group list: Get "https://192.168.1.100:6443/api?timeout=32s": dial tcp 192.168.1.100:6443: connect: connection refused
E0501 08:34:55.770441 11268 memcache.go:265] couldn't get current server API group list: Get "https://192.168.1.100:6443/api?timeout=32s": dial tcp 192.168.1.100:6443: connect: connection refused
E0501 08:34:55.771934 11268 memcache.go:265] couldn't get current server API group list: Get "https://192.168.1.100:6443/api?timeout=32s": dial tcp 192.168.1.100:6443: connect: connection refused
E0501 08:34:55.773435 11268 memcache.go:265] couldn't get current server API group list: Get "https://192.168.1.100:6443/api?timeout=32s": dial tcp 192.168.1.100:6443: connect: connection refused
E0501 08:34:55.774822 11268 memcache.go:265] couldn't get current server API group list: Get "https://192.168.1.100:6443/api?timeout=32s": dial tcp 192.168.1.100:6443: connect: connection refused
这应该是 API Server 没有启动,再看看K8S系统错误日志:
[root@master ~]# journalctl -f -u kubelet
... 其他信息
5月 01 08:34:42 master kubelet[972]: E0501 08:34:42.560018 972 pod_workers.go:1300] "Error syncing pod, skipping" err="failed to \"CreatePodSandbox\" for \"kube-scheduler-master_kube-system(4302dec0d7a2b0f4438374ffc19ef0be)\" with CreatePodSandboxError: \"Failed to create sandbox for pod \\\"kube-scheduler-master_kube-system(4302dec0d7a2b0f4438374ffc19ef0be)\\\": rpc error: code = Unknown desc = failed to get sandbox image \\\"registry.k8s.io/pause:3.6\\\": failed to pull image \\\"registry.k8s.io/pause:3.6\\\": failed to pull and unpack image \\\"registry.k8s.io/pause:3.6\\\": failed to resolve reference \\\"registry.k8s.io/pause:3.6\\\": failed to do request: Head \\\"https://asia-east1-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\\\": dial tcp 142.251.8.82:443: i/o timeout\"" pod="kube-system/kube-scheduler-master" podUID="4302dec0d7a2b0f4438374ffc19ef0be"
... 其他信息
过滤乱七八糟的错误日志,基本都在说无法使用connect: connection refused,但中间的错误可以看大是一个docke image pull不下来,肯定是在外网,所以我们可以使用阿里云镜像拿下来编辑一下名称。
解决办法01:
- 修改
/etc/containerd/config.toml
配置文件,执行命令如下所示:
sed -i 's/registry.k8s.io\/pause:3.6/registry.aliyuncs.com\/google_containers\/pause:3.9/g' /etc/containerd/config.toml
- 重启containerd
[root@master ~]# systemctl restart containerd
但我这个config.toml没有源设置的地方懒得找了,直接使用上面分析的方法pull在改tag
解决办法02:
[root@master ~]# ctr -n k8s.io images pull -k registry.aliyuncs.com/google_containers/pause:3.6
[root@master ~]# ctr -n k8s.io images tag registry.aliyuncs.com/google_containers/pause:3.6 registry.k8s.io/pause:3.6
# 重命名镜像registry.aliyuncs.com/google_containers/pause:3.6的tag为registry.k8s.io/pause:3.6
[root@master ~]# systemctl restart containerd
我就是这个办法解决的。