简体   繁体   English

如果没有为定义为 NodePort 的 k8 服务定义 nodeport no 会发生什么?

[英]What will happen if nodeport no is not define for k8 service which defined as NodePort?

Suppose I have 4 deployment files and for that I have 1 combined service file which will create service objects for all 4 services(deployment.yaml).假设我有 4 个部署文件,为此我有 1 个组合服务文件,它将为所有 4 个服务(deployment.yaml)创建服务对象。 Now I want to expose only 1 service pod as NodePort service, for which I have nodeport defined along with port and target port.现在我只想公开 1 个服务 pod 作为 NodePort 服务,为此我定义了 nodeport 以及端口和目标端口。 for rest of the 3 services I have only defined port and target port and not the nodeport.对于其余的 3 个服务,我只定义了端口和目标端口,而不是节点端口。 Question is, in this case whether the K8 master assign some random nodeport for rest of the 3 services for which nodeport not defined?问题是,在这种情况下,K8 主节点是否会为未定义节点端口的其余 3 个服务分配一些随机节点端口? Service.YAML:服务.YAML:

I can always declare 4 nodePorts for 4 services.我总是可以为 4 个服务声明 4 个 nodePort。 But How K8s Master will handle below manifest is more I am interested to explore for my app deployment但是 K8s Master 如何处理下面的清单是我更感兴趣的探索我的应用程序部署

apiVersion: v1
kind: Service
metadata:
  name: myapp-uwsgi-service
  namespace: myspace
  labels:
    central-app: myapp-uwsgi
spec:
  clusterIP: 10.3.0.106
  type: NodePort
  selector:
    central-app: configuration-uwsgi
  ports:
    -
      name: service-app-1
      port: 10010
      targetPort: 10010
      nodePort: 32123
    -
      name: service-app-2
      port: 10011
      targetPort: 10011
    -
      name: service-app-3
      port: 10012
      targetPort: 10012
    -
      name: service-app-4
      port: 10013
      targetPort: 10013

My expectation and understanding is that rest of the 3 service-app will assigned with some random nodePort from K8s master.我的期望和理解是,其余 3 个服务应用程序将分配一些来自 K8s 主节点的随机 nodePort。

Service type nodeport would assign random ports to others port defined in the service YAML.服务类型 nodeport 会将随机端口分配给服务 YAML 中定义的其他端口。 In your case you would end up with four nodeports在你的情况下,你最终会得到四个节点端口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM