使用minikube从docker hub中提取私有图像

时间:2016-12-09 11:48:27

标签: kubernetes dockerhub minikube

我在macOS 10.12上使用minikube并尝试使用在docker hub上托管的私有映像。我知道minikube会启动一个VM,据我所知,它将是我本地kubernetes集群的唯一节点,它将托管我的所有pod。

我读到我可以通过运行eval $(minikube docker-env)来使用VM的docker运行时。所以我使用这些变量从我的本地docker运行时更改为另一个。运行docker images我可以看到更改已经有效完成。

我的下一步是使用docker login登录docker hub,然后手动拉取我的图片,结果没有错误。在那之后,我认为图像将由群集中的任何pod使用,但我总是得到ImagePullBackOff。我也尝试通过minikube ssh ssh进入虚拟机,结果是一样的,图像可供使用,但出于某种原因,我不知道它拒绝使用它。 / p>

如果有帮助,这是我的部署描述文件:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 1
template:
  metadata:
    labels:
      app: nginx
  spec:
    containers:
    - name: nginx
      image: godraude/nginx
      imagePullPolicy: Always
      ports:
      - containerPort: 80
      - containerPort: 443

这是kubectl describe pod <podname>

的输出
Events:
  FirstSeen LastSeen    Count   From            SubobjectPath       Type        Reason      Message
  --------- --------    -----   ----            -------------       --------    ------      -------
  1m        1m      1   {default-scheduler }                Normal      Scheduled   Successfully assigned web-deployment-2451628605-vtbl8 to minikube
  1m        23s     4   {kubelet minikube}  spec.containers{nginx}  Normal      Pulling     pulling image "godraude/nginx"
  1m        20s     4   {kubelet minikube}  spec.containers{nginx}  Warning     Failed      Failed to pull image "godraude/nginx": Error: image godraude/nginx not found
  1m        20s     4   {kubelet minikube}              Warning     FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "nginx" with ErrImagePull: "Error: image godraude/nginx not found"

  1m    4s  5   {kubelet minikube}  spec.containers{nginx}  Normal  BackOff     Back-off pulling image "godraude/nginx"
  1m    4s  5   {kubelet minikube}              Warning FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "nginx" with ImagePullBackOff: "Back-off pulling image \"godraude/nginx\""

2 个答案:

答案 0 :(得分:2)

我认为你需要的是创建一个秘密来告诉kube它可以从哪里获取你的私人图像及其凭据

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

以下命令列出你的秘密

kubectl get secret
NAME            TYPE                      DATA      AGE
my-secret   kubernetes.io/dockercfg   1         100d

现在在部署定义中你需要定义使用的秘密

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 1
template:
  metadata:
    labels:
      app: nginx
  spec:
    containers:
    - name: nginx
      image: godraude/nginx
      imagePullPolicy: Always
      ports:
      - containerPort: 80
      - containerPort: 443
    imagePullSecrets:
      - name: my-secret

答案 1 :(得分:1)

The problem was the image pull policy. It was set to Always so docker was trying to pull the imagen even if it was present. Setting imagePullPolicy: Never solved the issue.