您好 kubernetes 开发者,
如果在 kubernetes 中部署 pod,我会收到错误“ImagePullBackOff”。 拉入 docker 从 git-hub 存储库获取镜像是没有问题的。但是我的配置有什么问题吗?
我尝试了此解决方法,使用以下命令创建密钥。
kubectl create secret docker-registry secretkey \
--docker-server=registry.hub.docker.com \
--docker-username=reponame \
--docker-password=repopassword \
--docker-email=repoemail
这是创建 kubernetes pod 的 yaml 文件。
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
io.kompose.service: gps-restful-server
name: gps-restful-server
spec:
containers:
- image: tux/gps:latest
name: gps-restful-server
ports:
- containerPort: 8080
resources: {}
volumeMounts:
- mountPath: /var/www/html/modules
name: gps-modules
- mountPath: /var/www/html/profiles
name: gps-profile
- mountPath: /var/www/html/themes
name: gps-theme
- mountPath: /var/www/html/sites
name: gps-sites
imagePullPolicy: Always
restartPolicy: OnFailure
imagePullSecrets:
- name: secretkey
volumes:
- name: gps-modules
persistentVolumeClaim:
claimName: gps-modules
- name: gps-profile
persistentVolumeClaim:
claimName: gps-profile
- name: gps-theme
persistentVolumeClaim:
claimName: gps-theme
- name: gps-sites
persistentVolumeClaim:
claimName: gps-sites
status: {}
要在 kubernetes 中部署 pod,我执行命令:
kubectl create -f gps-restful-server-pod.yaml.
从 pod 获取状态:
kubectl get all
NAME READY STATUS RESTARTS AGE
pod/telemetry-restful-server 0/1 ImagePullBackOff 0 12m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1h
吊舱描述:
kubectl describe pod gps-restful-server
Name: gps-restful-server
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: minikube/192.168.178.92
Start Time: Thu, 14 Feb 2019 16:56:25 +0100
Labels: io.kompose.service=gps-restful-server
Annotations: <none>
Status: Pending
IP: 172.17.0.3
Containers:
gps-restful-server:
Container ID:
Image: tux/gps:latest
Image ID:
Port: 8080/TCP
Host Port: 0/TCP
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-4t28k (ro)
/var/www/html/modules from gps-modules (rw)
/var/www/html/profiles from gps-profile (rw)
/var/www/html/sites from gps-sites (rw)
/var/www/html/themes from gps-theme (rw)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
gps-modules:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: gps-modules
ReadOnly: false
gps-profile:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: gps-profile
ReadOnly: false
gps-theme:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: gps-theme
ReadOnly: false
gps-sites:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: gps-sites
ReadOnly: false
default-token-4t28k:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-4t28k
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 4m default-scheduler Successfully assigned default/gps-restful-server to minikube
Normal Pulling 2m (x4 over 4m) kubelet, minikube pulling image "tux/gps:latest"
Warning Failed 2m (x4 over 4m) kubelet, minikube Failed to pull image "tux/gps:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for tux/gps, repository does not exist or may require 'docker login'
Warning Failed 2m (x4 over 4m) kubelet, minikube Error: ErrImagePull
Warning Failed 2m (x6 over 4m) kubelet, minikube Error: ImagePullBackOff
Normal BackOff 2m (x7 over 4m) kubelet, minikube Back-off pulling image "tux/gps:latest"
如何从 kubernetes 中的 docker-hub 拉取镜像?
图像 tux/gps:latest 不存在,因为它是虚拟值。 ImagePullBackoff的解决方案:
imagePullSecret:
- 名称:秘钥
imagebackpulloff
可能由以下原因造成:
当你在 kubernetes 中遇到 imagepullbackoff 错误时,要么是 docker 仓库名称指定错误,要么是镜像标签不正确。
返回您的 docker hub 并确认标签版本正确。
如果镜像标签是V3,而你在kubernetes部署清单中指定了V1,它会大喊大叫。
还要仔细检查存储库名称以及部署清单中的内容。
这些小疏忽可能会让人头疼,难以排除故障。
Kubernetes 中的“ImagePullBackOff”错误消息表示指定的 pod 无法从容器注册表中拉取它应该运行的容器镜像。发生此错误的原因有多种,例如图像名称不正确、身份验证问题或容器注册表的连接问题。
欲了解更多详情,请查看以下链接: 如何检查图像拉回