I'm trying to build a Kube.netes job on the fly by using the Kube.netes client in C# ( https://github.com/kube.netes-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).
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.
The k8s client creates the pod & job successfully but I get the following error in Lens:
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=kube.netes.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=kube.netes.io/dockerconfigjson
Are you specifying the correct path for config.json? If you ran the command you've provided, that is not valid. You have to determine the correct path for this.
C:\Users\<USER_NAME>\.docker\config.json
/Users/<USER_NAME>/.docker/config.json
/home/<USER_NAME>/.docker/config.json
You will then run:
kubectl create secret generic regcred --from-file=.dockerconfigjson=<PATH_HERE> --type=kubernetes.io/dockerconfigjson
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 ImagePullPolicy of the Container object should be equal to "Never" .
new V1Container
{
ImagePullPolicy = "Never",
Name = name,
Image = image,
...
}
Here the best possible answer is to copy the username and password and encode them into base64 into the.dockerconfigjson and copy the whole.dockerconfigjson file and convert it into base64 and copy that encoded text and paste in YAML and apply. Now your deployment will be successfully deployed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.