<p>I'm trying to build a Kubernetes job on the fly by using the Kubernetes client in C# (<a href="https://github.com/kubernetes-client/csharp" rel="nofollow noreferrer">https://github.com/kubernetes-client/csharp</a>). I get an error when the job is trying to pull the image from the repo.</p>
<p>The image I'm trying to attach to the job is situated in the local docker repo. Deploying the job to the namespace is no problem; this works just fine, but during the build is throws an error in Lens (see image).</p>
<p><a href="https://i.stack.imgur.com/zjErV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zjErV.png" alt="enter image description here" /></a></p>
<p>The code for building the job:</p>
<pre><code>        var job = new V1Job
        {
            ApiVersion = &quot;batch/v1&quot;,
            Kind = &quot;Job&quot;,
            Metadata = new V1ObjectMeta
            {
                Name = name,
                Labels = new Dictionary&lt;string, string&gt;(),
            },
            Spec = new V1JobSpec
            {
                BackoffLimit = backoffLimit,
                TtlSecondsAfterFinished = 0,
                Template = new V1PodTemplateSpec
                {
                    Spec = new V1PodSpec
                    {
                        Tolerations = new List&lt;V1Toleration&gt;(),
                        Volumes = new List&lt;V1Volume&gt;
                        {
                            new V1Volume
                            {
                                Name = &quot;podinfo&quot;,
                                DownwardAPI = new V1DownwardAPIVolumeSource
                                { 
                                    Items = new V1DownwardAPIVolumeFile[]
                                    {
                                        new V1DownwardAPIVolumeFile { Path = &quot;namespace&quot;, FieldRef = new V1ObjectFieldSelector(&quot;metadata.namespace&quot;) },
                                        new V1DownwardAPIVolumeFile { Path = &quot;name&quot;, FieldRef = new V1ObjectFieldSelector(&quot;metadata.name&quot;) },
                                    },
                                },
                            },
                        },
                        Containers = new[]
                        {
                            new V1Container
                            {
                                Name = &quot;tapereader-job-x-1&quot;,
                                Image = &quot;tapereader_sample_calculation&quot;,
                                Resources = new V1ResourceRequirements
                                {
                                    Limits = new Dictionary&lt;string, ResourceQuantity&gt;
                                    {
                                        { &quot;cpu&quot;, new ResourceQuantity(&quot;4&quot;) },
                                        { &quot;memory&quot;, new ResourceQuantity(&quot;4G&quot;) },
                                    },
                                    Requests = new Dictionary&lt;string, ResourceQuantity&gt;
                                    {
                                        { &quot;cpu&quot;, new ResourceQuantity(&quot;0.5&quot;) },
                                        { &quot;memory&quot;, new ResourceQuantity(&quot;2G&quot;) },
                                    },
                                },
                                VolumeMounts = new List&lt;V1VolumeMount&gt;
                                {
                                    new V1VolumeMount { Name = &quot;podinfo&quot;, MountPath = &quot;/etc/podinfo&quot;, ReadOnlyProperty = true },
                                },
                                Env = new List&lt;V1EnvVar&gt;(),
                            },
                        },
                        RestartPolicy = &quot;Never&quot;,
                    },
                },
            },
        };

        await Client.CreateNamespacedJobAsync(job, &quot;local-tapereader&quot;);
</code></pre>
<p>The container is ok, it is present in Docker Desktop (local repo) and I can build &amp; run it without any problems - it also executes the way it should in Docker desktop.</p>
<p><a href="https://i.stack.imgur.com/BDiDk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BDiDk.png" alt="enter image description here" /></a></p>
<p>The k8s client creates the pod &amp; job successfully but I get the following error in Lens:
<a href="https://i.stack.imgur.com/vZcHm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vZcHm.png" alt="enter image description here" /></a></p>
<p>So basically, it states that access was denied? How can I overcome this issue?</p>
<p>I already tried to add creds but this doesn't work</p>
<blockquote>
<p>kubectl create secret generic regcred
--from-file=.dockerconfigjson=pathto.docker\config.json --type=kubernetes.io/dockerconfigjson</p>
</blockquote>
<p>UPDATE:</p>
<p>I actually ran the following, like zero0 suggested:</p>
<blockquote>
<p>kubectl create secret generic regcred
--from-file=.dockerconfigjson=C:\Users\&lt;USER_NAME&gt;\.docker\config.json --type=kubernetes.io/dockerconfigjson</p>
</blockquote>

verlic
<p>Found the solution. The image resides in the local repo of Docker Desktop. Because of this the image doesn't have to be pulled. To avoid the image pull, the parameter <strong>ImagePullPolicy</strong> of the Container object should be equal to <strong>&quot;Never&quot;</strong>.</p>
<pre><code>new V1Container
{
 ImagePullPolicy = &quot;Never&quot;,
 Name = name,
 Image = image,
 ...
}
</code></pre>
