<p>I have a simple Kubernetes job (based on the <a href="http://kubernetes.io/docs/user-guide/jobs/work-queue-2/" rel="nofollow noreferrer">http://kubernetes.io/docs/user-guide/jobs/work-queue-2/</a> example) which uses a Docker image that I have placed as a public image on my dockerhub account. It all loks like this:</p>

<p><strong>job.yaml</strong>:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: job-wq-2
spec:
  parallelism: 2
  template:
    metadata:
      name: job-wq-2
    spec:
      containers:
      - name: c
        image: jonalv/job-wq-2
      restartPolicy: OnFailure
</code></pre>

<p>Now I want to try to instead use a private Docker registry which requires authentication as in:</p>

<p><code>docker login https://myregistry.com</code></p>

<p>But I can't find anything about how I add username and password to my job.yaml file. How is it done?</p>

<p>You need to use <a href="http://kubernetes.io/docs/user-guide/images/#specifying-imagepullsecrets-on-a-pod" rel="noreferrer">ImagePullSecrets</a>.</p>

<p>Once you create a secret object, you can refer to it in your pod spec (the <code>spec</code> value that is the parent of <code>containers</code>:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: job-wq-2
spec:
  parallelism: 2
  template:
    metadata:
      name: job-wq-2
    spec:
      imagePullSecrets:
      - name: myregistrykey
      containers:
      - name: c
        image: jonalv/job-wq-2
      restartPolicy: OnFailure
</code></pre>

<p>Ofcourse, you'll have to create the secret (as per the docs). This is what this will look like:</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: myregistrykey
  namespace: mynamespace
data:
  .dockerconfigjson: UmVhbGx5IHJlYWxseSByZWVlZWVlZWVlZWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx5eXl5eXl5eXl5eXl5eXl5eXl5eSBsbGxsbGxsbGxsbGxsbG9vb29vb29vb29vb29vb29vb29vb29vb29vb25ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubmdnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cgYXV0aCBrZXlzCg==
type: kubernetes.io/dockerconfigjson
</code></pre>

<p>The value of <code>.dockerconfigjson</code> is a base64 encoding of this file: <code>.docker/config.json</code>.</p>

<p>The key point: <strong>A job spec contains a pod spec</strong>. So whatever knowledge you gain about pod specs can be applied to jobs as well.</p>
