当前位置: 首页 > 知识库问答 >
问题:

服务类型为NodePort并同时指定了port和targetPort意味着什么?

雷硕
2023-03-14
spec:
  type: NodePort
  ports:
  - port: 27018
    targetPort: 27017
    protocol: TCP
nodePort     The port on each node on which this service is exposed when type=NodePort or LoadBalancer. Usually
integer      assigned by the system. If specified, it will be allocated to the service if unused or else creation of the
             service will fail. Default is to auto-allocate a port if the ServiceType of this Service requires one. More info: 
             http://kubernetes.io/docs/user-guide/services#type--nodeport

port         The port that will be exposed by this service.
integer

targetPort   Number or name of the port to access on the pods targeted by the service. Number must be in the range 1
IntOrString  to 65535. Name must be an IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the
             target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map).
             This field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field.
             More info: http://kubernetes.io/docs/user-guide/services#defining-a-service

我的理解是,集群之外的客户机将“看到”的端口将是文档中定义的30000-32767范围内动态分配的端口。这将使用一些我还不明白的魔法流到给定节点上的targetport(在本例中是27017)。

那么这里的端口用于什么呢?

共有1个答案

范霄
2023-03-14

为了更好地解释这个概念,我将服务的NodePort概念可视化。

正如@Fishi在他的回答中提到的,NodePort允许向外部客户端公开k8s主机端口(也就是NodePort)。客户机可以直接访问nodeport,k8s将通信转发到必要的端口。

K8s在其所有节点上保留一个nodeport。所有运行服务的节点都打开此端口。

 类似资料:
  • 我想创建一个

  • 问题内容: 我了解这是用来创建别名的。因此,将一个长名称别名为一个短名称是有意义的。但是,我看到一个查询 ,这意味着什么? 问题答案: 可以以多种方式使用别名,而不仅仅是缩短长列名。 在这种情况下,您的示例意味着您将返回一列始终包含的列,并且其别名/列名称为。 当您使用计算值(例如)时,也可以使用别名。

  • 本文向大家介绍微服务的端到端测试意味着什么?相关面试题,主要包含被问及微服务的端到端测试意味着什么?时的应答技巧和注意事项,需要的朋友参考一下 端到端测试 验证工作流中的所有流程,以检查一切是否按预期工作。它还确保系统以统一的方式工作,从而满足业务需求。

  • 根据C 11标准(草案n3337)§5/9: -如果两个操作数的类型相同,则无需进一步转换。 -否则,如果两个操作数都具有有符号整数类型或都具有无符号整数类型,则整数转换秩较小的操作数类型应转换为秩较大的操作数类型。 -否则,如果具有无符号整数类型的操作数的秩大于或等于另一个操作数类型的秩,则应将具有有符号整数类型的操作数转换为具有无符号整数类型的操作数的类型。 -否则,如果有符号整数类型的操作数

  • 我在Spring批处理代码中遇到了一个错误:创建名为“itemReader”(在类路径资源中定义)的bean时出错,未能将“$Proxy0”类型的属性值转换为属性“preparedStatementSetter”所需的类型。 这是我的ItemReader代码: 这是我的ReaderSqlParameterSetter类: 谁能帮帮我吗?