解决k3d或者k3s搭建k8s集群在发布镜像过程中提示ImagePullBackOff问题

笔者尝试在k3d搭建的k8s集群中发布tomcat服务,结果迟迟无法启动,以下为创建容器到解决的过程:

1. 发布tomcat指令

kubectl create deployment tomcat --image=tomcat --port=8080

kubectl expose deployment tomcat --port=8080 --target-port=8080

kubectl exec deployment/tomcat -c tomcat -- /bin/bash -c 'mkdir webapps/ROOT; echo "kt-connect demo v1" > webapps/ROOT/index.html'

执行前两步日志显示正常执行,但是执行第三步的报错提示:error: unable to upgrade connection: container not found ("tomcat")

2. 使用kubectl get pods指令提示状态为ImagePullBackOff

kubectl get pods

3. 考虑是因为镜像无法拉取导致的,查看pod描述,事件提示Back-off pulling image "tomcat"

kubectl describe pod tomcat

4. 考虑是因为镜像无法拉取导致的,解决办法,在服务中配置加速节点【也可以配置私服地址】

/etc/rancher/k3s/registries.yaml

mirrors:
  docker.io:
    endpoint:
      - "https://fsp2sfpr.mirror.aliyuncs.com/"

5. 在次执行查看kubectl get pods

6. 再次查看describe事件状态,圆满解决

参考:

https://forums.rancher.cn/t/centos-k3s-k8s/3156

https://forums.rancher.cn/t/k3s-pod/198

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章