<p>I've been trying to run a deployment using a private init container image with little success, I always get this error:</p>

<pre><code>Failed to pull image "private/app": Error: image private/app:latest not found
Error syncing pod, skipping: failed to "StartContainer" for "app" with ErrImagePull: "Error: image private/app:latest not found"
</code></pre>

<p>Here is my deployment:</p>

<pre><code>"kind": "Deployment"
"apiVersion": "extensions/v1beta1"
"metadata":
  "name": "tomcat"
  "creationTimestamp": null
"spec":
  "replicas": 1
  "template":
    "metadata":
      "creationTimestamp": null
      "labels":
        "service": "tomcat"
      "annotations":
        "pod.beta.kubernetes.io/init-containers": '[
          {
            "name": "app",
            "image": "private/app",
            "imagePullPolicy": "IfNotPresent"
          }
        ]'
    "spec":
      "containers":
        - "name": "tomcat"
          "image": "private/tomcat"
          "ports":
            - "containerPort": 8080
              "protocol": "TCP"
      "imagePullSecrets":
        - "name": "my-secret"
      "restartPolicy": "Always"
  "strategy": {}
"status": {}
</code></pre>

<p>I also tried it with the change suggested here <a href="https://stackoverflow.com/questions/42422892/kubernetes-init-containers-using-a-private-repo">kubernetes init containers using a private repo</a>:</p>

<pre><code>"pod.beta.kubernetes.io/init-containers": '[
  {
    "name": "app",
    "image": "private/app",
    "imagePullPolicy": "IfNotPresent",
    "imagePullSecrets": [
      {
        "name": "my-secret"
      }
    ]
  }
]'
</code></pre>

<p>But still nothing...</p>

<p>Note that I have tested this deployment without the init container and the image pulling was successful.</p>

<p>Also note that this is a simplified version of my actual configuration, in the real configuration there is volume mounting for both containers and some env variables.</p>

<p>How do I configure "imagePullSecrets" for an init-container?</p>

<p><strong>Edit:</strong>
I was asking around in the kubernetes slack channel and it seems I forgot to give permissions to the cluster docker user (CI docker user if you would) permissions to this hub repository, once I did that the "imagePullPolicy" on the init container was redundant, the one on the "template" > "spec" was enough.</p>

<p>Thanks @koki, wherever you might be.</p>

<p>You should using <code>secret</code> object.</p>

<p>something like this:</p>

<pre><code>  kubectl create secret docker-registry myregistry \
  --docker-server=https://example.io \
  --docker-username=foo \
  --docker-password=boosecret \
  --docker-email=example@boo.com
</code></pre>

<p>And use it , in another object like this:</p>

<pre><code>  imagePullSecrets:
  - name: myregistry
</code></pre>
