Pulling an Image from Private Registry in Kubernetes cronjob fails

3/28/2018

I am pulling an image from a private repository on gitlab and running a cronjob in kubernetes. Since it is a private repo I would also have to supply the imagePullSecrets. but I noticed it gives an error because a cronjob doesn't accept the imagePullSecrets tag. It gives the following error. Does that mean I can't use an image from a private repository in a cronjob?

error: error validating "cron.yml": error validating data: ValidationError(CronJob.spec.jobTemplate.spec.template.spec.containers[0]): unknown field "imagePullSecrets" in io.k8s.api.core.v1.Container; if you choose to ignore these errors, turn validation off with --validate=false
-- Anshul Tripathi
docker
gitlab
kubectl
kubernetes

1 Answer

3/28/2018

The imagePullSecrets field is not a per container field - you need to set that at CronJob.spec.jobTemplate.spec.template.spec.imagePullSecrets instead of CronJob.spec.jobTemplate.spec.template.spec.containers.imagePullSecrets. You can see an example for a Pod here.

-- dippynark
Source: StackOverflow