I'm trying to build a Kubernetes job on the fly by using the Kubernetes client in C# (<https://github.com/kubernetes-client/csharp>). I get an error when the job is trying to pull the image from the repo.

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).

[![enter image description here](https://i.stack.imgur.com/zjErV.png)](https://i.stack.imgur.com/zjErV.png)

The code for building the job:

```
        var job = new V1Job
        {
            ApiVersion = "batch/v1",
            Kind = "Job",
            Metadata = new V1ObjectMeta
            {
                Name = name,
                Labels = new Dictionary<string, string>(),
            },
            Spec = new V1JobSpec
            {
                BackoffLimit = backoffLimit,
                TtlSecondsAfterFinished = 0,
                Template = new V1PodTemplateSpec
                {
                    Spec = new V1PodSpec
                    {
                        Tolerations = new List<V1Toleration>(),
                        Volumes = new List<V1Volume>
                        {
                            new V1Volume
                            {
                                Name = "podinfo",
                                DownwardAPI = new V1DownwardAPIVolumeSource
                                { 
                                    Items = new V1DownwardAPIVolumeFile[]
                                    {
                                        new V1DownwardAPIVolumeFile { Path = "namespace", FieldRef = new V1ObjectFieldSelector("metadata.namespace") },
                                        new V1DownwardAPIVolumeFile { Path = "name", FieldRef = new V1ObjectFieldSelector("metadata.name") },
                                    },
                                },
                            },
                        },
                        Containers = new[]
                        {
                            new V1Container
                            {
                                Name = "tapereader-job-x-1",
                                Image = "tapereader_sample_calculation",
                                Resources = new V1ResourceRequirements
                                {
                                    Limits = new Dictionary<string, ResourceQuantity>
                                    {
                                        { "cpu", new ResourceQuantity("4") },
                                        { "memory", new ResourceQuantity("4G") },
                                    },
                                    Requests = new Dictionary<string, ResourceQuantity>
                                    {
                                        { "cpu", new ResourceQuantity("0.5") },
                                        { "memory", new ResourceQuantity("2G") },
                                    },
                                },
                                VolumeMounts = new List<V1VolumeMount>
                                {
                                    new V1VolumeMount { Name = "podinfo", MountPath = "/etc/podinfo", ReadOnlyProperty = true },
                                },
                                Env = new List<V1EnvVar>(),
                            },
                        },
                        RestartPolicy = "Never",
                    },
                },
            },
        };

        await Client.CreateNamespacedJobAsync(job, "local-tapereader");

```

The container is ok, it is present in Docker Desktop (local repo) and I can build & run it without any problems - it also executes the way it should in Docker desktop.

[![enter image description here](https://i.stack.imgur.com/BDiDk.png)](https://i.stack.imgur.com/BDiDk.png)

The k8s client creates the pod & job successfully but I get the following error in Lens:
[![enter image description here](https://i.stack.imgur.com/vZcHm.png)](https://i.stack.imgur.com/vZcHm.png)

So basically, it states that access was denied? How can I overcome this issue?

I already tried to add creds but this doesn't work

> 
> kubectl create secret generic regcred
> --from-file=.dockerconfigjson=pathto.docker\config.json --type=kubernetes.io/dockerconfigjson
> 
> 
> 

UPDATE:

I actually ran the following, like zero0 suggested:

> 
> kubectl create secret generic regcred
> --from-file=.dockerconfigjson=C:\Users\<USER\_NAME>\.docker\config.json --type=kubernetes.io/dockerconfigjson
> 
> 
>