初始化 K8s 主节点时 报错failed to pull image registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.17

运行r如下命令初始化kubernetes的master节点

2025年3月12日更新:

阿里云的镜像仓库目前只给它自己云上的服务器使用了,建议更换华为云的镜像加速器
https://support.huaweicloud.com/usermanual-swr/swr_01_0045.html

kubeadm init \
  --kubernetes-version=v1.23.17 \
  --image-repository registry.aliyuncs.com/google_containers \
  --pod-network-cidr=10.100.0.0/16 \
  --service-cidr=10.200.0.0/16 \
  --service-dns-domain=ashm.com

出现的报错如下:

[init] Using Kubernetes version: v1.23.17
[preflight] Running pre-flight checks
        [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.17: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/kube-controller-manager:v1.23.17: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/kube-scheduler:v1.23.17: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/kube-proxy:v1.23.17: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/pause:3.6: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/etcd:3.5.6-0: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/coredns:v1.8.6: output: Error response from daemon: Get "https://registry.aliyuncs.com/v2/": dial tcp: lookup registry.aliyuncs.com on 192.168.133.2:53: server misbehaving
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

从错误日志中可以看出,kubeadm init 在尝试拉取 Kubernetes 镜像时出现了网络问题,无法连接到 registry.aliyuncs.com。这可能是由于 DNS 配置或网络连接问题引起的。我们可以通过以下步骤来解决这个问题。

1. 确认 Docker 服务已启用

首先,确保 Docker 服务已启用并正在运行。根据日志提示,Docker 服务虽然已启动,但没有设置为开机自启动。请运行以下命令:

sudo systemctl enable docker
sudo systemctl start docker

检查 Docker 服务状态:

sudo systemctl status docker

2. 检查 DNS 配置

确保 DNS 配置正确,能够解析 registry.aliyuncs.com。可以编辑 /etc/resolv.conf 文件来修改 DNS 服务器。例如:

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'

3. 测试网络连接

确认可以从命令行访问 registry.aliyuncs.com。你可以使用 curlping 命令来测试:

curl -I https://registry.aliyuncs.com
ping registry.aliyuncs.com

4. 手动拉取镜像

如果网络问题持续,可以尝试手动拉取所需的镜像,然后重新运行 kubeadm init

# 手动拉取所需的镜像
sudo kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.17

5. 尝试使用其他镜像仓库

如果阿里云镜像仓库持续无法访问,可以尝试使用官方的 Google Container Registry(GCR),但请注意 GCR 在国内可能访问较慢:

kubeadm init --kubernetes-version=v1.23.17 --pod-network-cidr=10.100.0.0/16 --service-cidr=10.200.0.0/16 --service-dns-domain=ashm.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值