How to access private Docker Hub repository from Kubernetes on Vagrant
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
To pull images from a private Docker Hub repository in Kubernetes running on Vagrant, you need to create a Kubernetes Secret containing your Docker Hub credentials and reference it in your pod spec with imagePullSecrets. Without this, Kubernetes gets ErrImagePull or ImagePullBackOff because the kubelet cannot authenticate with Docker Hub. The process is the same regardless of whether Kubernetes runs on Vagrant, cloud VMs, or bare metal.
Step 1: Create a Docker Registry Secret
This creates a Secret named dockerhub-secret in the current namespace containing your Docker Hub credentials.
Step 2: Reference the Secret in Pod Spec
The imagePullSecrets field tells the kubelet to use the Secret's credentials when pulling the image.
Step 3: Apply and Verify
Using with Deployments
Creating the Secret from Docker Config
If you have already logged in with docker login:
Using a Docker Hub Access Token (Recommended)
Personal access tokens are more secure than passwords:
Access tokens can be scoped and revoked without changing your password.
Attaching Secret to a Service Account
Instead of adding imagePullSecrets to every pod, attach it to the default service account:
Now all pods using the default service account automatically use the credentials:
Vagrant-Specific Considerations
Networking
Vagrant VMs need internet access to pull images from Docker Hub. If using a private network, configure a proxy or pre-pull images.
Pre-Pulling Images
Pre-pulling avoids repeated downloads and works offline after the initial pull.
Multiple Registries
List multiple secrets for pods that pull from different registries.
Verifying the Secret
Namespace Scope
Secrets are namespace-scoped. Create the secret in each namespace that needs it:
Common Pitfalls
- Wrong docker-server URL: For Docker Hub, use
https://index.docker.io/v1/. Other registries have different URLs (e.g.,ghcr.io,gcr.io). A wrong URL causes authentication failure even with correct credentials. - Secret in wrong namespace: If your pod is in namespace
stagingbut the secret is indefault, the pod cannot access it. Create the secret in the same namespace as the pod. - Expired access token: Docker Hub access tokens can expire. If pulls suddenly fail with
unauthorized, regenerate the token and update the secret. - Rate limiting: Docker Hub limits anonymous pulls to 100/6h and authenticated pulls to 200/6h. If you hit limits on Vagrant (multiple nodes pulling), use a pull-through cache or pre-pull images.
- Vagrant VM memory: Kubernetes + Docker + your application needs at least 4GB RAM. Underpowered VMs cause
OOMKillederrors that look like image pull failures.
Summary
- Create a
docker-registrySecret with Docker Hub credentials - Add
imagePullSecretsto the pod spec or patch the default service account - Use Docker Hub access tokens instead of passwords for better security
- Secrets are namespace-scoped. Create them in each namespace that needs them
- Ensure Vagrant VMs have internet access and sufficient resources (4GB+ RAM)
- Attach secrets to the default service account to avoid repeating
imagePullSecretsin every pod
Related reading
- How to access service created in another namespace
- How to access/expose kubernetes-dashboard service outside of a cluster?
- How to add flag to Kubernetes controller manager
- How to add kubernetes pods label to prometheus metrics?
- How to add a Container View programmatically
- How to add initial users when starting a RabbitMQ Docker container?
- How to access remote server with local phpMyAdmin client?
- How to access Spring-boot JMX remotely

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.