Kubernetes-部署Pod时出现错误消息ImagePullBackOff

时间:2019-02-14 19:43:52

标签: image kubernetes

您好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容器的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.

从窗格中获取状态:

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提取图像?

2 个答案:

答案 0 :(得分:1)

该问题是由于键<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/date_home_textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginEnd="126dp" android:text="Today's Date" android:textSize="30sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/textView3" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/mass_attendance_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:text="Mass Attendance" app:layout_constraintBottom_toTopOf="@+id/guideline2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/Shift_home" app:layout_constraintTop_toTopOf="@+id/guideline5" /> <TextView android:id="@+id/textView" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="8dp" android:layout_marginTop="4dp" android:layout_marginEnd="16dp" android:layout_marginBottom="8dp" android:text="Location" android:textSize="24sp" android:textStyle="bold" app:layout_constrainedWidth="true" app:layout_constraintBottom_toTopOf="@+id/guideline5" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/barrier2" /> <Spinner android:id="@+id/Shift_home" android:layout_width="0dp" android:layout_height="45dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" app:layout_constraintBottom_toTopOf="@+id/guideline2" app:layout_constraintEnd_toStartOf="@+id/mass_attendance_button" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_chainStyle="spread_inside" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline5" /> <android.support.constraint.Barrier android:id="@+id/barrier2" android:layout_width="wrap_content" android:layout_height="wrap_content" app:barrierDirection="bottom" app:constraint_referenced_ids="textView3" tools:layout_editor_absoluteY="823dp" /> <android.support.constraint.Guideline android:id="@+id/guideline2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.36" /> <android.support.constraint.Guideline android:id="@+id/guideline5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.24" /> <android.support.constraint.Barrier android:id="@+id/barrier" android:layout_width="wrap_content" android:layout_height="wrap_content" app:barrierDirection="top" app:constraint_referenced_ids="guideline5" tools:layout_editor_absoluteX="67dp" tools:layout_editor_absoluteY="81dp" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:layout_marginEnd="4dp" android:text="Date:" android:textSize="30sp" app:layout_constraintEnd_toStartOf="@+id/date_home_textview" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> 的值错误引起的。

  

容器的image属性支持与docker命令相同的语法,包括私有注册表和标签。

k8s Images

答案 1 :(得分:1)

图像tux / gps:latest不存在,因为它是虚拟值。 ImagePullBackoff解决方案:

  1. 确保您的映像指向最新版本的repouser / reponame:latest
  2. 创建一个秘密的docker-registry(请参见上方)
  3. 服务器地址[docker-hub registry]
  4. 在pod yaml文件中添加以下属性(如上所示):

imagePullSecrets:
  -名称:secretkey