如何从 Vagrant 上的 Kubernetes 访问私有 Docker Hub 存储库 [英] How to access private Docker Hub repository from Kubernetes on Vagrant

查看:17
本文介绍了如何从 Vagrant 上的 Kubernetes 访问私有 Docker Hub 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从我的私有 Docker Hub 存储库中提取到在 Vagrant 上运行的本地 Kubernetes 设置:

I am failing to pull from my private Docker Hub repository into my local Kubernetes setup running on Vagrant:

podhellonode-n1hox"中的容器hellonode"正在等待启动:图像不能拉

Container "hellonode" in pod "hellonode-n1hox" is waiting to start: image can't be pulled

无法拉取镜像用户名/hellonode":错误:镜像用户名/hellonode:最新未找到

Failed to pull image "username/hellonode": Error: image username/hellonode:latest not found

我已经按照此处的描述在本地通过 Vagrant 设置了 Kubernetes 并创建一个名为dockerhub"的秘密,使用 kubectl 创建秘密 docker-registry dockerhub --docker-server=https://registry.hub.docker.com/ --docker-username=username --docker-password=... --docker-email=... 我提供了它作为图像拉取密码.

I have set up Kubernetes locally via Vagrant as described here and created a secret named "dockerhub" with kubectl create secret docker-registry dockerhub --docker-server=https://registry.hub.docker.com/ --docker-username=username --docker-password=... --docker-email=... which I supplied as the image pull secret.

我正在运行 Kubernetes 1.2.0.

I am running Kubernetes 1.2.0.

推荐答案

从 Kubernetes YAML 中提取私有的 DockerHub 托管镜像:

To pull a private DockerHub hosted image from a Kubernetes YAML:

运行这些命令:

DOCKER_REGISTRY_SERVER=docker.io
DOCKER_USER=Type your dockerhub username, same as when you `docker login`
DOCKER_EMAIL=Type your dockerhub email, same as when you `docker login`
DOCKER_PASSWORD=Type your dockerhub pw, same as when you `docker login`

kubectl create secret docker-registry myregistrykey 
  --docker-server=$DOCKER_REGISTRY_SERVER 
  --docker-username=$DOCKER_USER 
  --docker-password=$DOCKER_PASSWORD 
  --docker-email=$DOCKER_EMAIL

如果您在 DockerHub 上的用户名是 DOCKER_USER,并且您的私有仓库名为 PRIVATE_REPO_NAME,并且您要拉取的镜像被标记为 latest>,创建这个 example.yaml 文件:

If your username on DockerHub is DOCKER_USER, and your private repo is called PRIVATE_REPO_NAME, and the image you want to pull is tagged as latest, create this example.yaml file:

apiVersion: v1
kind: Pod
metadata:
  name: whatever
spec:
  containers:
    - name: whatever
      image: DOCKER_USER/PRIVATE_REPO_NAME:latest
      imagePullPolicy: Always
      command: [ "echo", "SUCCESS" ]
  imagePullSecrets:
    - name: myregistrykey

然后运行:

kubectl create -f example.yaml

这篇关于如何从 Vagrant 上的 Kubernetes 访问私有 Docker Hub 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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