提问者:小点点

kubernetes无法提取本地映像


我在一台机器上使用kubernetes进行测试,我已经从nginx docker映像构建了一个自定义映像,但是当我尝试在kubernetes中使用映像时,我得到了一个映像拉取错误?????

我的豆荚

kind: Pod
apiVersion: v1
metadata:
  name: yumserver
  labels:
    name: frontendhttp
spec:
  containers:
    - name: myfrontend
      image: my/nginx:latest
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
      - mountPath: "/usr/share/nginx/html"
        name: mypd
  imagePullSecrets:
    - name: myregistrykey

  volumes:
    - name: mypd
      persistentVolumeClaim:
       claimName: myclaim-1

我的KUBERNETES指挥官

kubectl创建-f pod yumserver。亚马尔

错误

kubectl describe pod yumserver


Name: yumserver
Namespace: default
Image(s):   my/nginx:latest
Node:       127.0.0.1/127.0.0.1
Start Time: Tue, 26 Apr 2016 16:31:42 +0100
Labels:     name=frontendhttp
Status:     Pending
Reason:     
Message:    
IP:     172.17.0.2
Controllers:    <none>
Containers:
  myfrontend:
    Container ID:   
    Image:      my/nginx:latest
    Image ID:       
    QoS Tier:
      memory:       BestEffort
      cpu:      BestEffort
    State:      Waiting
      Reason:       ErrImagePull
    Ready:      False
    Restart Count:  0
    Environment Variables:
Conditions:
  Type      Status
  Ready     False 
Volumes:
  mypd:
    Type:   PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  myclaim-1
    ReadOnly:   false
  default-token-64w08:
    Type:   Secret (a secret that should populate this volume)
    SecretName: default-token-64w08
Events:
  FirstSeen LastSeen    Count   From            SubobjectPath           Type        Reason          Message
  --------- --------    -----   ----            -------------           --------    ------          -------
  13s       13s     1   {default-scheduler }                    Normal      Scheduled       Successfully assigned yumserver to 127.0.0.1
  13s       13s     1   {kubelet 127.0.0.1}                 Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  12s       12s     1   {kubelet 127.0.0.1} spec.containers{myfrontend} Normal      Pulling         pulling image "my/nginx:latest"
  8s        8s      1   {kubelet 127.0.0.1} spec.containers{myfrontend} Warning     Failed          Failed to pull image "my/nginx:latest": Error: image my/nginx:latest not found
  8s        8s      1   {kubelet 127.0.0.1}                 Warning     FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "myfrontend" with ErrImagePull: "Error: image my/nginx:latest not found"

共3个答案

匿名用户

所以你的机器上有图像。然而,它仍然试图从Docker Hub中提取图像,这可能不是您在单机设置中想要的。这是因为最新标记将imagePullPolicy设置为始终隐式。您可以尝试将其设置为IfNotPresent显式或更改为除latest之外的其他标记Timo Reimann 4月28日7:16

出于某种原因,Timo Reimann只是在上面发布了这个评论,但它绝对应该是这个问题的官方答案,所以我再次发布。

匿名用户

在构建图像之前,运行eval$(minikube docker env)。

完整答案:https://stackoverflow.com/a/40150867

匿名用户

无论您是否正在使用minikube,这都应该有效:

  1. 启动本地注册表容器:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
docker tag <local-image-repository>:<local-image-tag> localhost:5000/<local-image-name>

如果本地图像的标记为

docker tag <local-image-repository> localhost:5000/<local-image-name>
docker push localhost:5000/<local-image-name>

这将自动将latest标记添加到localhost:5000/

...
spec:
  containers:
  - name: <name>
    image: localhost:5000/<local-image-name>
    imagePullPolicy: IfNotPresent
...

就这样。现在您的ImagePuller错误应该得到解决。

注意:如果群集中有多个主机,并且希望使用特定的主机来托管注册表,只需将上述所有步骤中的localhost替换为托管注册表容器的主机的主机名。在这种情况下,您可能需要允许HTTP(非HTTPS)连接到注册表:

5(可选)。允许连接到工作节点中不安全的注册表:

sudo echo '{"insecure-registries":["<registry-hostname>:5000"]}' > /etc/docker/daemon.json