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

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
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐