从本地docker镜像运行kubectl?

时间:2018-08-13 16:15:49

标签: macos docker kubernetes

如何引用存在的本地图像?

kubectl run u --rm -i --tty --image my_local_image -- bash

ImagePullBackOffkubectl中的结果显然是试图从远程存储库而不是本地寄存器中提取。

answer没有帮助,后续内容涉及minikube和kubernetes。

一些事件日志

Events:
  Type     Reason                 Age               From                         Message
  ----     ------                 ----              ----                         -------
  Normal   Scheduled              1m                default-scheduler            Successfully assigned u-6988b9c446-zcp99 to docker-for-desktop
  Normal   SuccessfulMountVolume  1m                kubelet, docker-for-desktop  MountVolume.SetUp succeeded for volume "default-token-q2qm7"
  Normal   SandboxChanged         1m                kubelet, docker-for-desktop  Pod sandbox changed, it will be killed and re-created.
  Normal   Pulling                23s (x3 over 1m)  kubelet, docker-for-desktop  pulling image "centos_postgres"
  Warning  Failed                 22s (x3 over 1m)  kubelet, docker-for-desktop  Failed to pull image "centos_postgres": rpc error: code = Unknown desc = Error response from daemon: pull access denied for centos_postgres, repository does not exist or may require 'docker login'
  Warning  Failed                 22s (x3 over 1m)  kubelet, docker-for-desktop  Error: ErrImagePull
  Normal   BackOff                9s (x5 over 1m)   kubelet, docker-for-desktop  Back-off pulling image "centos_postgres"
  Warning  Failed                 9s (x5 over 1m)   kubelet, docker-for-desktop  Error: ImagePullBackOff

1 个答案:

答案 0 :(得分:5)

Kubernetes Pod有一个imagePullPolicy字段。如果将其设置为Never,它将永远不会尝试提取图像,并且要确保由kubelet使用的docker守护进程包含该图像。默认策略为IfNotPresent,如果docker守护程序中已存在映像,则该策略应与Never相同。仔细检查您的docker守护进程实际上是否包含您认为的内容,并确保您的imagePullPolicy设置为我提到的两个之一。

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-image
      image: local-image-name
      imagePullPolicy: Never