Home > OS >  How to specify the selectors for a nodeport service through the command line?
How to specify the selectors for a nodeport service through the command line?

Time:04-10

I'm trying to accomplish the following: Create a new service to access the web application using the service-definition-1.yaml file

  Name: webapp-service
  Type: NodePort
  targetPort: 8080
  port: 8080
  nodePort: 30080
  selector: simple-webapp

I ran the command

kubectl create service nodeport webapp-service --tcp=8080:8080 --node-port=30080

and got everything I wanted. However, I have to manually create & edit the yaml file to add the selector: simple-webapp.

I was curious if I could specify the selectors for a service through the command line?

CodePudding user response:

I think the concept you are looking for is "Labels and Selectors"

See: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/

kubectl get pods -l environment=production,tier=frontend

CodePudding user response:

Try: kubectl create service nodeport webapp-service --tcp 8080:8080 --node-port 30080 --dry-run=client -o yaml | kubectl set selector --local -f - app=simple-webapp -o yaml

  • Related