K8S执行完毕kubectl init xxx 执行 kubectl get ns 报错才connect: connection refused

问题场景:

在安装完毕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:

  1. 修改 /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 

image.png

  1. 重启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

我就是这个办法解决的。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值