-->

Friday, November 5, 2021

[Solved] ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec

 Issue:- 

Issue occured when i tried to deployed the deployment yaml file on the kubernetes.

kind: Deployment  
 metadata:  
  name: jenkins  
  namespace: jenkins  
  template:  
   metadata:  
    labels:  
     app: jenkins  
   spec:  
    volumes:  
    - name: jenkins-home  
     persistentVolumeClaim:  
      claimName: pvc-nfs-pv1  
    containers:  
     - name: jenkins  
      image: jenkins/jenkins:lts  
      lifecycle:  
       postStart:  
        exec:  
         command: ["/bin/sh", "-c", "/var/jenkins_home/ip-update.sh"]  
      env:  
       - name: JAVA_OPTS  
        value: -Djenkins.install.runSetupWizard=false  
      ports:  
       - name: http-port  
        containerPort: 8080  
       - name: jnlp-port  
        containerPort: 50000  
      volumeMounts:  
       - name: jenkins-home  
        mountPath: /var/jenkins_home  


Error:- 

ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec


Cause:-

The issue is with the deployment yaml file as evident in the error message, as the deployment.spec.selector was missing in the configuration or it should not be empty. Because using the selector Deployment finds which pods to manage.

 spec:  
  replicas: 1  
  selector:  
   matchLabels:  
    app: jenkins  


Resolution:-

So i update the Deployment yaml file as per the code with the deployment.spec.selector which resolved the issue.

kind: Deployment  
 metadata:  
  name: jenkins  
  namespace: jenkins  
 spec:  
  replicas: 1  
  selector:  
   matchLabels:  
    app: jenkins  
  template:  
   metadata:  
    labels:  
     app: jenkins  
   spec:  
    volumes:  
    - name: jenkins-home  
     persistentVolumeClaim:  
      claimName: pvc-nfs-pv1  
    containers:  
     - name: jenkins  
      image: jenkins/jenkins:lts  
      lifecycle:  
       postStart:  
        exec:  
         command: ["/bin/sh", "-c", "/var/jenkins_home/ip-update.sh"]  
      env:  
       - name: JAVA_OPTS  
        value: -Djenkins.install.runSetupWizard=false  
      ports:  
       - name: http-port  
        containerPort: 8080  
       - name: jnlp-port  
        containerPort: 50000  
      volumeMounts:  
       - name: jenkins-home  
        mountPath: /var/jenkins_home  

0 comments:

Post a Comment