【问题标题】:How to specify the selectors for a nodeport service through the command line?如何通过命令行指定节点端口服务的选择器?
【发布时间】:2022-12-21 19:25:26
【问题描述】:

我正在努力实现以下目标: 使用 service-definition-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

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

【问题讨论】:

  • 您也可以考虑使用 kubectl expose,但它不可能提供 nodeport 号码,只能随机提供。

标签: kubernetes


【解决方案1】:

尝试:

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2015-09-19
      • 2011-04-10
      相关资源
      最近更新 更多