ImagePullSecrets GCR
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If your Kubernetes cluster needs to pull private images from Google Container Registry, the cluster must present valid registry credentials. In Kubernetes, the usual mechanism is an imagePullSecret referenced by a Pod or ServiceAccount. For GCR, that secret is typically created from a Google service account key or from Docker credentials that can authenticate to gcr.io.
What imagePullSecrets Does
When Kubernetes starts a Pod, the kubelet may need to authenticate to the registry before it can download the image. An imagePullSecret stores those registry credentials in a Kubernetes Secret of type kubernetes.io/dockerconfigjson.
Without it, private GCR images often fail with image-pull errors such as ImagePullBackOff.
Create a Secret for GCR
A common pattern uses a Google service account JSON key. The Docker username for this case is _json_key, and the password is the JSON key content.
Create the secret in the namespace where the Pod will run.
Use the Secret in a Pod
Reference it in the Pod spec.
Now the Pod can use that secret when pulling the image.
Attach It to a ServiceAccount Instead
If many Pods in the same namespace need the same registry credentials, attaching the secret to a ServiceAccount is cleaner than repeating imagePullSecrets in every manifest.
Then reference the ServiceAccount from your workload.
Namespace Scope Matters
Secrets are namespace-scoped. A secret created in default is not visible in production.
That is a common reason the configuration "looks right" but image pulls still fail. Make sure the secret exists in the same namespace as the Pod.
Troubleshooting Pull Failures
If the Pod still cannot pull the image, inspect it:
Look for messages such as:
- '
ErrImagePull' - '
ImagePullBackOff' - unauthorized or forbidden registry responses
Also verify that:
- the image path is correct
- the service account key has permission to access the registry
- the secret name is spelled correctly
- the Pod and secret are in the same namespace
GCR Versus Artifact Registry
Some teams still use GCR, while others have moved to Google Artifact Registry. The Kubernetes secret pattern is similar, but the registry host changes. So always match the --docker-server value to the actual registry domain you are pulling from.
Verify the Secret Object Type
A quick sanity check is to confirm that Kubernetes created the secret as a Docker config secret and not as a generic opaque secret.
You should see the type kubernetes.io/dockerconfigjson. If the type is wrong, the kubelet cannot use it for registry authentication even if the secret data exists.
Common Pitfalls
A common mistake is creating the secret in the wrong namespace.
Another mistake is referencing imagePullSecrets correctly but using credentials that do not actually have permission to the target image.
Developers also often copy GCR examples to Artifact Registry without changing the registry host, which results in authentication failures that look mysterious at first.
Summary
- Private GCR images need registry credentials in Kubernetes.
- Create a
docker-registrysecret and reference it withimagePullSecrets. - ServiceAccount attachment is cleaner when multiple Pods need the same secret.
- The secret must exist in the same namespace as the Pod.
- If pulls fail, inspect the Pod events and verify both registry path and permissions.
Related reading
- Import data to config map from kubernetes secret
- In Kubernetes, how can i have an access mode to allow one pod at a time to write and many pods to read only?
- In Kubernetes, how to setup multiple hosts in one ingress with let''s encrypt certificates
- In Kubernetes, what is the difference between ResourceQuota vs LimitRange objects
- Import broker definitions into Dockerized RabbitMQ
- Import data.sql MySQL Docker Container
- Implement exclusive access to an EFS/NFS directory
- Implementing Licencing mechanism for a Software

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.