Pulling an Image from Private Registry in Kubernetes cronjob fails
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When a Kubernetes CronJob fails to pull an image from a private container registry, the pod enters an ImagePullBackOff or ErrImagePull state. The root cause is almost always a missing or misconfigured imagePullSecrets on the CronJob's pod template. Unlike Deployments, CronJobs create new pods on each schedule tick, so every pod needs valid credentials. The fix involves creating a Docker registry secret and referencing it in the CronJob spec — or attaching it to the ServiceAccount so all pods in the namespace inherit it automatically.
The Error
When you describe the failed pod, you see:
The pod status shows ImagePullBackOff, meaning Kubernetes tried to pull the image, got a 401 Unauthorized, and is now backing off before retrying.
Fix 1: Add imagePullSecrets to the CronJob
Create a Docker registry secret and reference it in the CronJob's pod template:
The imagePullSecrets field must be at the pod spec level (spec.jobTemplate.spec.template.spec), not at the container level.
Fix 2: Attach Secret to ServiceAccount
Instead of adding imagePullSecrets to every CronJob, attach the secret to the default ServiceAccount. Every pod in the namespace then inherits it:
Now any CronJob in that namespace pulls private images without needing explicit imagePullSecrets in the spec.
Fix 3: ECR, GCR, and ACR-Specific Solutions
Cloud registries have their own authentication mechanisms:
For GKE with Google Container Registry, configure Workload Identity. For AKS with Azure Container Registry, use az aks update --attach-acr.
Debugging Steps
Common Pitfalls
- Wrong namespace: The secret must be in the same namespace as the CronJob. Secrets are namespace-scoped and cannot be shared across namespaces without tools like Sealed Secrets or External Secrets.
- Expired credentials: Cloud registry tokens (ECR, GCR) expire. A static secret with an expired token causes recurring failures. Use a token refresh CronJob or workload identity.
- Typo in secret name:
imagePullSecretsreferences the secret by name. A typo means Kubernetes silently ignores the missing secret and fails with 401. - imagePullSecrets at wrong level: Placing
imagePullSecretsunderspec.jobTemplate.specinstead ofspec.jobTemplate.spec.template.spechas no effect. It must be in the pod template spec. - Private registry with self-signed cert: Even with correct credentials, a self-signed TLS certificate causes
x509: certificate signed by unknown authority. Configure the node's container runtime to trust the CA.
Summary
- CronJob image pull failures from private registries are caused by missing
imagePullSecrets - Create a
docker-registrysecret and reference it in the CronJob's pod template spec - Attach the secret to the ServiceAccount to avoid repeating it in every workload
- Cloud registries (ECR, GCR, ACR) need token refresh or workload identity because credentials expire
- Always verify the secret exists in the correct namespace and the name matches exactly
Related reading
- Pulling images from private registry in Kubernetes
- Pulling local repository docker image from kubernetes
- Puppeteer waitForSelector works in local Docker container but times out when deployed on Kubernetes
- PVC Events waiting for a volume to be created, either by external provisioner csi.vsphere.vmware.com or manually created by system administrator
- Pulling from private registry fails - Unsupported docker v1 repository request
- Push docker image to amazon ecs repository
- Pushing to Git returning Error Code 403 fatal HTTP request failed
- Pushing to Git returning Error Code 403 fatal HTTP request failed

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.