Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling private image from docker hub using minikube

I'm using minikube on macOS 10.12 and trying to use a private image hosted at docker hub. I know that minikube launches a VM that as far as I know will be the unique node of my local kubernetes cluster and that will host all my pods.

I read that I could use the VM's docker runtime by running eval $(minikube docker-env). So I used those variables to change from my local docker runtime to the other. Running docker images I could see that the change was done effectively.

My next step was to log in at docker hub using docker login and then pulling my image manually, which ended without error. After that I thought that the image will by ready to by be used by any pod in the cluster but I'm always getting ImagePullBackOff. I also tried to ssh into the VM via minikube ssh and the result is the same, the image is there to be used but for some reason I don't know it's refusing to use it.

In case it helps, this is my deployment description file:

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

And this is the output of 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\""
like image 338
Godraude Avatar asked Dec 09 '16 11:12

Godraude


1 Answers

i think what u need is to create a secrete which will tell kube from where it can pull your private image and its credentials

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

below command to list your secretes

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

now in deployment defination u need to define whcih secret to use

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
like image 71
Deepak Avatar answered Sep 20 '22 19:09

Deepak