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 
  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

我就是这个办法解决的。

相关推荐
JunLan~26 分钟前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
海岛日记2 小时前
centos一键卸载docker脚本
linux·docker·centos
小袁搬码4 小时前
Windows中指定路径安装DockerDesktop
windows·docker·容器·docker desktop
qq_312920114 小时前
docker 部署 kvm 图形化管理工具 WebVirtMgr
运维·docker·容器
踏雪Vernon4 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
条纹布鲁斯5 小时前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
工业3D_大熊7 小时前
3D可视化引擎HOOPS Luminate场景图详解:形状的创建、销毁与管理
java·c++·3d·docker·c#·制造·数据可视化
szc17677 小时前
docker 相关命令
java·docker·jenkins
CP-DD7 小时前
Docker 容器化开发 应用
运维·docker·容器
Stark-C7 小时前
万物皆可Docker,在NAS上一键部署最新苹果MacOS 15系统
macos·docker·策略模式