Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes pull images from private registry fails --> unknown field "imagePullPolicy"

I'm trying to pull an image from my priavte harbor registry. In Kubernetes I created a secret first as explained in this documentation:

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

Then I tried to implement that into my deployment.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-k8s-test9
  namespace: k8s-test9
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-k8s-test9
    spec:
      containers:
      - name: nginx-k8s-test9
        image: my-registry.com/nginx-test/nginx:1.14.2
      imagePullSecrets:
      - name: harborcred
        imagePullPolicy: Always
        volumeMounts:
          - name: webcontent
            mountPath: usr/share/nginx/html
        ports:
        - containerPort: 80
      volumes:
        - name: webcontent
          configMap:
            name: webcontent
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: webcontent
  namespace: k8s-test9
  annotations:
    volume.alpha.kubernetes.io/storage-class: default
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 5Gi

When I try to create the deployment I get the following error message:

error: error validating "deployment.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "imagePullPolicy" in io.k8s.api.core.v1.LocalObjectReference, ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "ports" in io.k8s.api.core.v1.LocalObjectReference, ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "volumeMounts" in io.k8s.api.core.v1.LocalObjectReference]; if you choose to ignore these errors, turn validation off with --validate=false

I guess it's a yaml issue somehow but I don't know where it should be.

like image 794
Timo Antweiler Avatar asked Oct 31 '25 22:10

Timo Antweiler


1 Answers

And here is the solution:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-k8s-test9
  namespace: k8s-test9
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-k8s-test9
    spec:
      containers:
      - name: nginx-k8s-test9
        image: my-registry.com/nginx-test/nginx:1.14.2
        volumeMounts:
          - name: webcontent
            mountPath: usr/share/nginx/html
        ports:
        - containerPort: 80
      volumes:
        - name: webcontent
          configMap:
            name: webcontent
      imagePullSecrets:
      - name: harborcred-test
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: webcontent
  namespace: k8s-test9
  annotations:
    volume.alpha.kubernetes.io/storage-class: default
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 5Gi

The imagePullSecrets section was not at the right place.

like image 58
Timo Antweiler Avatar answered Nov 02 '25 20:11

Timo Antweiler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!