Sun
Sun

Reputation: 251

imagePullSecrets not working with Kind deployment

I'm tying to create a deployment with 3 replicas, whcih will pull image from a private registry. I have stored the credentials in a secret and using the imagePullSecrets in the deployment file. Im getting below error in the deploy it.

error: error validating "private-reg-pod.yaml": error validating data: [ValidationError(Deployment.spec): unknown field "containers" in io.k8s.api.apps.v1.DeploymentSpec, ValidationError(Deployment.spec): unknown field "imagePullSecrets" in io.k8s.api.apps.v1.DeploymentSpec, ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec, ValidationError(Deployment.spec): missing required field "template" in io.k8s.api.apps.v1.DeploymentSpec]; if you choose to ignore these errors, turn validation off with --validate=false

Any help on this?

Below is my deployment file :

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-pod-deployment
  labels:
    app: test-pod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-pod
  template:
    metadata:
      labels:
        app: test-pod
    spec:
      containers:
      - name: test-pod
    image: <private-registry>
  imagePullSecrets:
  - name: regcred

Thanks, Sundar

Upvotes: 19

Views: 28149

Answers (4)

Mohammad Mansouri
Mohammad Mansouri

Reputation: 21

Both @Jakub-Bujny and @itmaven are correct. The indentation is really important in creating and using .yaml (or .yml) file. The yaml file has been parsed based on these indentations. So, both of these are correct:

1) spec: imagePullSecrets: - name: regcred containers: - name: test-pod image: 2)

spec:        
    containers:
    - name: test-pod
      image: <private-registry>          
    imagePullSecrets:
    - name: regcred

Note: before you used the imagePullSecrets you have to create that using the following code:

kubectl create secret docker-registry <private-registry> --docker-server= 
<cluster_CA_domain>:[some port] --docker-username=<user_name> --docker- 
password=<user_password> --docker-email=<user_email>

also check if the imagePullSecrets was created successfully using the following code:

kubectl get secret

Upvotes: 1

itmaven
itmaven

Reputation: 151

Very common issue with kubernetes Deployment.

The valid format for pulling image from private repository in your Kubernetes Deployment file is:

spec:
  imagePullSecrets:
  - name: <your secret name>    
  containers:

Upvotes: 15

Mohammed Ali
Mohammed Ali

Reputation: 1

Please make sure you have created the secret,then please try to make it like the below .

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-pod-deployment
  labels:
    app: test-pod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-pod
  template:
    metadata:
      labels:
        app: test-pod
    spec:
      containers:
       - name: test-pod
         image: nginx
      imagePullSecrets:
       - name: regcred

Upvotes: 0

Jakub Bujny
Jakub Bujny

Reputation: 4628

Image section should be placed in container specification. ImagePullSecret should be placed in spec section so proper yaml file looks like this (please note indent):

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-pod-deployment
  labels:
    app: test-pod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-pod
  template:
    metadata:
      labels:
        app: test-pod
    spec:
      containers:
       - name: test-pod
         image: <private-registry>
      imagePullSecrets:
       - name: regcred

Upvotes: 32

Related Questions