Home > Software engineering >  Creating "imagePullSecret" to work with the deployment.yaml file which contains an image f
Creating "imagePullSecret" to work with the deployment.yaml file which contains an image f

Time:11-07

I have created a deployment yaml file with an image name with my private docker repository. when running the command :

 kubectl get pods

I see that the status of the created pod from that deployment file is ImagePullBackOff. from what I have read it is because I am pulling the image from a private registry without imagePullSecret.

how do I create "imagePullSecret" as a yaml file to work with the deployment.yaml file which contains an image from the private repository? or is it a feild which should be part of the deployment file?

CodePudding user response:

First you create the imagePullSecret from your docker

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

Alternatively, you can create the imagePullSecret by providing the required arguments in the command line

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

Then use the imagePullSecret name in the pod manifest

apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: regcred

Reference:

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

CodePudding user response:

There is a field in spec of the pod called imagePullSecrets, whichi you could define with your deployment yaml:

imagePullSecrets:
- name: registry-secret

Then you can define the missing "imagePullSecret" as a yaml file:

apiVersion: v1
kind: Secret
metadata:
  name: registry-secret
  namespace: xxx-namespace
data:
  .dockerconfigjson: UmVhbGx5IHJlYWxseSByZWVlZWVlZWVlZWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx5eXl5eXl5eXl5eXl5eXl5eXl5eSBsbGxsbGxsbGxsbGxsbG9vb29vb29vb29vb29vb29vb29vb29vb29vb25ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubmdnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cgYXV0aCBrZXlzCg==
type: kubernetes.io/dockerconfigjson

The data field .dockerconfigjson can be created from this docs.

  • Related