K8S error validating data: ValidationError(Deployment.spec): missing required field selector

The following error is reported

This is an error when I execute the pod copy of the deployment controller. The meaning of the error is:
deployment verification error. The selector parameter must be specified in the deployment spec module.

Original yaml file

In Deployment.spec In the module, only the number of replicas is specified, and the replica label needs to be specified to match the deployment controller

apiVersion: apps/v1     #Api interface version
kind: Deployment #define controller
metadata:      
 name: nginx-deployment #deployment name
spec:       
 replicas: 3 #Under the specific parameter information spec, only the number of replicas is specified, you also need to specify the replica tag to match the Deployment controller

 template:
   metadata: 
     labels: 
       app: nginx-deployment   
   spec:
     containers:    	
       - name: nginx-deployment  	
         image: nginx:1.7.9  
         ports:   	 
           - containerPort: 80

Solution: modify yaml file

As shown in the figure above, write the selector tag parameters of the full spec according to the tags on the picture, matching with pod and deployment

Execute yaml script

kubectl apply -f deployment.yaml --record

Read More: