如何在Vagrant上从Kubernetes访问私有Docker Hub存储库 [英] How to access private Docker Hub repository from Kubernetes on Vagrant
问题描述
我无法从私有Docker Hub存储库中拉到我在Vagrant上运行的本地Kubernetes设置中:
I am failing to pull from my private Docker Hub repository into my local Kubernetes setup running on Vagrant:
容器"hellonode-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,并创建了带有 kubectl的名为"dockerhub"的秘密创建秘密docker-registry dockerhub --docker-server = https://registry.hub.docker.com/ --docker-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屋!