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

我就是这个办法解决的。

相关推荐
景天科技苑2 小时前
【云原生开发】K8S多集群资源管理平台架构设计
云原生·容器·kubernetes·k8s·云原生开发·k8s管理系统
wclass-zhengge3 小时前
K8S篇(基本介绍)
云原生·容器·kubernetes
颜淡慕潇3 小时前
【K8S问题系列 |1 】Kubernetes 中 NodePort 类型的 Service 无法访问【已解决】
后端·云原生·容器·kubernetes·问题解决
川石课堂软件测试5 小时前
性能测试|docker容器下搭建JMeter+Grafana+Influxdb监控可视化平台
运维·javascript·深度学习·jmeter·docker·容器·grafana
昌sit!11 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
追风林12 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
A ?Charis14 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
城南vision14 小时前
Docker学习—Docker核心概念总结
java·学习·docker
wclass-zhengge14 小时前
Docker篇(Docker Compose)
运维·docker·容器
北漂IT民工_程序员_ZG15 小时前
k8s集群安装(minikube)
云原生·容器·kubernetes