如何通过命令行指定节点端口服务的选择器?

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

我正在尝试完成以下任务: 使用服务定义-1.yaml 文件

创建一个新服务来访问 Web 应用程序
  Name: webapp-service
  Type: NodePort
  targetPort: 8080
  port: 8080
  nodePort: 30080
  selector: simple-webapp

我运行命令

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

得到了我想要的一切。但是,我必须手动创建和编辑 yaml 文件以添加选择器:simple-webapp.

我很好奇是否可以通过命令行指定服务的选择器?

我认为您正在寻找的概念是“标签和选择器”

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

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

尝试: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