Skip to content

Instantly share code, notes, and snippets.

@toddlers
Last active December 14, 2020 08:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save toddlers/bb09002ffdc27fba6b7cef920fda2041 to your computer and use it in GitHub Desktop.
Save toddlers/bb09002ffdc27fba6b7cef920fda2041 to your computer and use it in GitHub Desktop.
docker hub with kubernetes in GKE
  • Step by step how to pull a private DockerHub hosted image in a Kubernetes YML.
export DOCKER_REGISTRY_SERVER=https://index.docker.io/v1/
export DOCKER_USER=Type your dockerhub username, same as when you `docker login`
export DOCKER_EMAIL=Type your dockerhub email, same as when you `docker login`
export DOCKER_PASSWORD=Type your dockerhub pw, same as when you `docker login`
export SECRETNAME=acmeorg
  • You can now add the secret to your Kubernetes configuration. You can add it to the default service account with the following command:
kubectl patch serviceaccount default -p "{\"imagePullSecrets\": [{\"name\": \"$SECRETNAME\"}]}"
kubectl create secret docker-registry $SECRETNAME \
  --docker-server=$DOCKER_REGISTRY_SERVER \
  --docker-username=$DOCKER_USER \
  --docker-password=$DOCKER_PASSWORD \
  --docker-email=$DOCKER_EMAIL

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 "latest", create this dummy.yaml file: If you images are named like orgname/consul . Use the same in the image url

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

Then run:

kubectl create -f dummy.yaml

@sudhirkilani1431987
Copy link

I executed above procedure to pull my image from docker hub.
But i dont see images successfully pulled.
For ex,After above procedure to pull image from Docker hub,If i execute docker images I dont see Image that I pulled.
Please help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment