Kubernetes无法从Docker Hub存储库中提取图像 [英] Kubernetes can't pull images from docker hub repository

查看:106
本文介绍了Kubernetes无法从Docker Hub存储库中提取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们好,希望您一切顺利!

Hello Guys hope you well!

我需要我的主计算机命令从服务器从我的Docker集线器仓库中提取映像,并且出现以下错误,它不允许从服务器从仓库中提取图像,但是当我进入从服务器时,需要手动进行操作拉他拉

I need the that my master machine order the slave to pull the image from my docker hub repo and I get the error below, It doesn't let the slave pull from the repo, but when I go to the slave, manually pull he pulls

这来自kubernetes管理员:

This from kubernetes master:

第一行是对pod my-app-6c99bd7b9c-dqd6l的描述,该代码现在正在运行,因为我是从Docker集线器中手动提取映像的,但我希望Kubernetes可以这样做.

The first lines are a describe from pod my-app-6c99bd7b9c-dqd6l which is running now because I pulled manually the image from the docker hub, but I want Kubernetes to do it.

Events:
  Type     Reason          Age                            From                           Message
  ----     ------          ----                           ----                           -------
  Normal   Scheduled       <unknown>                      default-scheduler              Successfully assigned default/my-app2-74969ddd4f-l6d6l to kubeslave.machine.pt
  Normal   SandboxChanged  <invalid>                      kubelet, kubeslave.machine.pt  Pod sandbox changed, it will be killed and re-created.
  Warning  Failed          <invalid> (x3 over <invalid>)  kubelet, kubeslave.machine.pt  Failed to pull image "bedjase/repository/my-java-app:my-java-app": rpc error: code = Unknown desc = Error response from daemon: pull access denied for bedjase/repository/my-java-app, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
  Warning  Failed          <invalid> (x3 over <invalid>)  kubelet, kubeslave.machine.pt  Error: ErrImagePull
  Normal   BackOff         <invalid> (x7 over <invalid>)  kubelet, kubeslave.machine.pt  Back-off pulling image "bedjase/repository/my-java-app:my-java-app"
  Warning  Failed          <invalid> (x7 over <invalid>)  kubelet, kubeslave.machine.pt  Error: ImagePullBackOff
  Normal   Pulling         <invalid> (x4 over <invalid>)  kubelet, kubeslave.machine.pt  Pulling image "bedjase/repository/my-java-app:my-java-app"
[root@kubernetes ~]# kubectl get pods
NAME                       READY   STATUS             RESTARTS   AGE
my-app-6c99bd7b9c-dqd6l    1/1     Running            0          14m
my-app2-74969ddd4f-l6d6l   0/1     ImagePullBackOff   0          2m20s
nginx-86c57db685-bxkpl     1/1     Running            0          8h

这是来自奴隶的:

[root@kubeslave docker]# docker pull bedjase/repository:my-java-app
my-java-app: Pulling from bedjase/repository
50e431f79093: Already exists
dd8c6d374ea5: Already exists
c85513200d84: Already exists
55769680e827: Already exists
e27ce2095ec2: Already exists
5943eea6cb7c: Already exists
3ed8ceae72a6: Already exists
7ba151cdc926: Already exists
Digest: sha256:c765d09bdda42a4ab682b00f572fdfc4bbcec0b297e9f7716b3e3dbd756ba4f8
Status: Downloaded newer image for bedjase/repository:my-java-app
docker.io/bedjase/repository:my-java-app

我已经在docker hub repo的主服务器和从服务器中都进行了登录并成功. 都可以使用/etc/hosts,也可以连接节点并准备就绪:

I already made the login in both master and slave to docker hub repo and succeed. Both have /etc/hosts ok, also nodes are connected and ready:

[root@kubernetes ~]# kubectl get nodes
NAME                    STATUS   ROLES    AGE   VERSION
kubernetes.machine.pt   Ready    master   26h   v1.17.4
kubeslave.machine.pt    Ready    <none>   26h   v1.17.4

我在这里想漏点吗?

推荐答案

对于私有映像,您必须使用Docker Hub的usernamepassword创建一个secret,以便Kubernetes能够提取该映像.

For private images you must create a secret with username and password of Docker Hub to Kubernetes be able to pull the image.

下面的命令使用您的Docker Hub凭据创建一个秘密名称regcred,替换字段<<your-name>><your-password><your-email>:

The command bellow create a secret name regcred with your Docker Hub credentials, replace the fields <<your-name>>, <your-password> and <your-email>:

kubectl create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username=<your-name> --docker-password=<your-password> --docker-email=<your-email>

之后,您需要在pod/deployment规范中添加要使用此凭据的私有图像,以添加带有以上创建的凭据的imagePullSecrets的私有映像,请参见以下示例:

After that you need to add in your pod/deployment spec that you want to use this credentials to pull your private image adding the imagePullSecrets with the credentials created above, see this example:

apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: regcred

参考:

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-yours-secret

这篇关于Kubernetes无法从Docker Hub存储库中提取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆