![如何更改kubernetes默认暂停容器下载地址](https://linux22.com/image/790903/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9kubernetes%E9%BB%98%E8%AE%A4%E6%9A%82%E5%81%9C%E5%AE%B9%E5%99%A8%E4%B8%8B%E8%BD%BD%E5%9C%B0%E5%9D%80.png)
由于网络问题,我想将默认的 google pause 容器从官方地址更改为镜像地址。我试图v1.28.3
像这样更改 kubernetes 中的默认暂停容器地址:
root@k8sslave01:/var/lib/kubelet# cat /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.9"
当我重新启动 kubelet 服务时,该地址似乎不起作用。我应该怎么做才能更改 google pause 容器的默认地址?我也尝试添加--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
,但仍然无法解决问题,kubelet 日志显示错误:
root@k8sslave01:/etc/containerd# systemctl status kubelet -l --no-pager
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since Sun 2023-11-12 00:48:39 CST; 1min 21s ago
Docs: https://kubernetes.io/docs/
Main PID: 2436 (kubelet)
Tasks: 10 (limit: 2025)
Memory: 35.7M
CPU: 1.871s
CGroup: /system.slice/kubelet.service
└─2436 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.9 --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.679287 2436 kuberuntime_sandbox.go:72] "Failed to create sandbox for pod" err="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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\": dial tcp 64.233.188.82:443: i/o timeout" pod="reddwarf-monitor/prometheus-prometheus-node-exporter-j78z6"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.679310 2436 kuberuntime_manager.go:1166] "CreatePodSandbox for pod failed" err="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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\": dial tcp 64.233.188.82:443: i/o timeout" pod="reddwarf-monitor/prometheus-prometheus-node-exporter-j78z6"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.679358 2436 pod_workers.go:1300] "Error syncing pod, skipping" err="failed to \"CreatePodSandbox\" for \"prometheus-prometheus-node-exporter-j78z6_reddwarf-monitor(786d8b9f-483f-4868-a7e9-42c43997a204)\" with CreatePodSandboxError: \"Failed to create sandbox for pod \\\"prometheus-prometheus-node-exporter-j78z6_reddwarf-monitor(786d8b9f-483f-4868-a7e9-42c43997a204)\\\": 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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\\\": dial tcp 64.233.188.82:443: i/o timeout\"" pod="reddwarf-monitor/prometheus-prometheus-node-exporter-j78z6" podUID="786d8b9f-483f-4868-a7e9-42c43997a204"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.747517 2436 remote_runtime.go:193] "RunPodSandbox from runtime service failed" err="rpc error: code = DeadlineExceeded 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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\": dial tcp 64.233.188.82:443: i/o timeout"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.747582 2436 kuberuntime_sandbox.go:72] "Failed to create sandbox for pod" err="rpc error: code = DeadlineExceeded 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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\": dial tcp 64.233.188.82:443: i/o timeout" pod="kube-system/kube-proxy-cvrtf"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.747610 2436 kuberuntime_manager.go:1166] "CreatePodSandbox for pod failed" err="rpc error: code = DeadlineExceeded 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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\": dial tcp 64.233.188.82:443: i/o timeout" pod="kube-system/kube-proxy-cvrtf"
Nov 12 00:49:55 k8sslave01 kubelet[2436]: E1112 00:49:55.747691 2436 pod_workers.go:1300] "Error syncing pod, skipping" err="failed to \"CreatePodSandbox\" for \"kube-proxy-cvrtf_kube-system(175f3730-2bf2-4b56-8bbb-992b603edc93)\" with CreatePodSandboxError: \"Failed to create sandbox for pod \\\"kube-proxy-cvrtf_kube-system(175f3730-2bf2-4b56-8bbb-992b603edc93)\\\": rpc error: code = DeadlineExceeded 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://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/3.6\\\": dial tcp 64.233.188.82:443: i/o timeout\"" pod="kube-system/kube-proxy-cvrtf" podUID="175f3730-2bf2-4b56-8bbb-992b603edc93"
Nov 12 00:49:57 k8sslave01 kubelet[2436]: E1112 00:49:57.053066 2436 pod_workers.go:1300] "Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized" pod="calico-system/csi-node-driver-mgdpk" podUID="cf30fa63-9367-44fc-92da-9abaaec31115"
Nov 12 00:49:59 k8sslave01 kubelet[2436]: E1112 00:49:59.053229 2436 pod_workers.go:1300] "Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized" pod="calico-system/csi-node-driver-mgdpk" podUID="cf30fa63-9367-44fc-92da-9abaaec31115"
Nov 12 00:50:01 k8sslave01 kubelet[2436]: E1112 00:50:01.052851 2436 pod_workers.go:1300] "Error syncing pod, skipping" err="network is not ready: container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized" pod="calico-system/csi-node-driver-mgdpk" podUID="cf30fa63-9367-44fc-92da-9abaaec31115"
/etc/containerd/config.toml
我像这样覆盖了 containerd 配置:
[plugins."io.containerd.grpc.v1.cri"]
#sandbox_image = "k8s.m.daocloud.io/pause:3.6"
sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"
仍然没有修复此问题。这是kubeadm-flags.env
配置:
[root@k8s ~]# cat /var/lib/kubelet/kubeadm-flags.env
KUBELET_KUBEADM_ARGS="--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"
答案1
您需要将其应用到您的案例中,并且我没有足够的上下文来了解您的错误日志,但通常要更改 Kubernetes 中 Google 暂停容器的默认地址,请尝试以下步骤:
编辑 kubelet 配置文件(通常位于
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
或/etc/default/kubelet
取决于您的设置)。添加或修改该
KUBELET_EXTRA_ARGS
行以包含带有--pod-infra-container-image
所需镜像地址的标志。例如:
KUBELET_EXTRA_ARGS="--pod-infra-container-image=your-mirror-address/pause:your-version"
your-mirror-address
用镜像地址和your-version
所需版本替换。
- 保存更改并重新启动 kubelet 服务:
systemctl daemon-reload
systemctl restart kubelet
确保镜像地址可访问,并且该地址上有指定版本的暂停容器。这应该会更新新创建的 Pod 的暂停容器地址。
如果问题仍然存在,请检查 kubelet 日志中是否存在可能提供更多见解的错误或警告:
journalctl -u kubelet
注意:我们在 HostJane 服务在 Kubernetes 上部署应用程序时遇到了类似的问题,上述步骤成功更改了暂停容器的地址。希望对您有所帮助。