1. 报错信息:
- 使用 K8S 部署 spring boot 项目时,镜像一直 pull 失败
- 这里我使用的是本地自建的镜像仓库做镜像源
[root@master DockerSpringBootDemo]# kubectl get pod
NAME READY STATUS RESTARTS AGE
springbootdemo 0/1 ContainerCreating 0 5s
[root@master DockerSpringBootDemo]# kubectl describe pod springbootdemo
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m38s default-scheduler Successfully assigned default/springbootdemo to node02 # ⭐ pod 被调度给 node02,node02开始下载镜像
Warning Failed 63s (x2 over 114s) kubelet Failed to pull image "springbootdemo:v1.0": rpc error: code = Unknown desc = Error response from daemon: http: server gave HTTP response to HTTPS client
Warning Failed 63s (x2 over 114s) kubelet Error: ErrImagePull
Normal BackOff 49s (x2 over 114s) kubelet Back-off pulling image "springbootdemo:v1.0"
Warning Failed 49s (x2 over 114s) kubelet Error: ImagePullBackOff
Normal Pulling 34s (x3 over 2m37s) kubelet Pulling image "springbootdemo:v1.0"
2. 原因分析:
- 一定记得将集群中所有的 node 节点也修改镜像仓库源!
- 镜像的拉取是在Pod 调度之后的,也就是说真正 Pull 镜像的是 node 节点
- 踩坑:由于只改了 master 节点的镜像仓库源,会导致镜像一直下载失败
3. 解决方法:
给 kubernetes 集群的所有 节点都修改镜像源!
在 K8S 集群的 master 节点、node01节点、node02节点上操作
-
修改端口配置文件,将上面的阿里云仓库改成 自建的本地镜像仓库
[root@registry ~]# vim /etc/docker/daemon.json
{ "insecure-registries": ["192.168.10.110:5000"] }
注意这里是:
insecure-registries
-
重启docker
[root@registry ~]# systemctl daemon-reload [root@registry ~]# systemctl restart docker
-
查看此时使用的 Docker 镜像仓库
[root@registry ~]# docker info ... Insecure Registries: 192.168.10.174:5000 127.0.0.0/8 ...