问题
在引入阿里镜像加速器后,手动命令行部署nginx,发现pod的status为ImagePullBackOff
排查思路
1.使用kubectl describe pod web-64d985c689-49d4b
检查pod的一些信息,发现最关键的一句是:Failed to pull image "nignx": rpc error: code = Unknown desc = Error response from daemon: pull access denied for nignx, repository does not exist or may require 'docker login',原来是nginx拼写成了nignx
[root@k8s-master ~]# kubectl describe pod web-64d985c689-49d4b
Name: web-64d985c689-49d4b
Namespace: default
Priority: 0
Node: k8s-node1/192.168.1.166
Start Time: Sat, 15 Oct 2022 16:03:42 +0800
Labels: app=web
pod-template-hash=64d985c689
Annotations: <none>
Status: Pending
IP: 10.244.2.6
IPs:
IP: 10.244.2.6
Controlled By: ReplicaSet/web-64d985c689
Containers:
nignx:
Container ID:
Image: nignx
Image ID:
Port: <none>
Host Port: <none>
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-597tl (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-597tl:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-597tl
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 5m54s default-scheduler Successfully assigned default/web-64d985c689-49d4b to k8s-node1
Normal Pulling 3m6s (x4 over 5m53s) kubelet, k8s-node1 Pulling image "nignx"
Warning Failed 2m45s (x4 over 5m21s) kubelet, k8s-node1 Failed to pull image "nignx": rpc error: code = Unknown desc = Error response from daemon: pull access denied for nignx, repository does not exist or may require 'docker login'
Warning Failed 2m45s (x4 over 5m21s) kubelet, k8s-node1 Error: ErrImagePull
Normal BackOff 2m32s (x6 over 5m21s) kubelet, k8s-node1 Back-off pulling image "nignx"
Warning Failed 51s (x13 over 5m21s) kubelet, k8s-node1 Error: ImagePullBackOff
2.依次删除deployment、pod、service, 当删除了deployment的时候,pod也会自动被删除
root@k8s-master ~]# kubectl delete deployment web -n default
deployment.apps "web" deleted
[root@k8s-master ~]# kubectl get deployment -n default
No resources found in default namespace.
[root@k8s-master ~]# kubectl get pod -n default
No resources found in default namespace.
[root@k8s-master ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d15h
web1 NodePort 10.102.149.13 <none> 80:32398/TCP 14m
[root@k8s-master ~]# kubectl delete svc web1 -n default
service "web1" deleted
重新部署
先删除上次的yaml文件,再按照顺序依次部署,最后发现pod的状态是Running
[root@k8s-master ~]# ls
anaconda-ks.cfg web1.yaml web.yaml
[root@k8s-master ~]# rm -rf web*
[root@k8s-master ~]# ls
anaconda-ks.cfg
[root@k8s-master ~]# kubectl create deployment web --image=nginx --dry-run -o yaml > web.yaml
W1015 16:21:34.834821 55655 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@k8s-master ~]# ls
anaconda-ks.cfg web.yaml
[root@k8s-master ~]# kubectl apply -f web.yaml
deployment.apps/web created
[root@k8s-master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
web 0/1 1 0 15s
[root@k8s-master ~]# kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=web1 -o yaml > web1.yaml
[root@k8s-master ~]# ls
anaconda-ks.cfg web1.yaml web.yaml
[root@k8s-master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
web 1/1 1 1 84s
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
web-5dcb957ccc-hmx7h 1/1 Running 0 91s
[root@k8s-master ~]# kubectl apply -f web1.yaml
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
service/web1 configured
[root@k8s-master ~]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/web-5dcb957ccc-hmx7h 1/1 Running 0 112s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d15h
service/web1 NodePort 10.104.228.101 <none> 80:31425/TCP 35s
标签:pull,web,拼写错误,nignx,master,kubectl,k8s,root
From: https://www.cnblogs.com/my_captain/p/16794475.html