kubernetes服务中可以公开的端口数量是否有限制?

问题描述

我正在尝试在200个奇数端口上公开服务。这是示例服务yaml:

apiVersion: v1
kind: Service
Metadata:
  name: multiport-server-large-port
spec:
  type: NodePort
  selector:
    app: multiport-server-large-port
  ports:
  - port: 49152
    name: tcp-49152
  - port: 49153
    name: tcp-49153
  - port: 49154
    name: tcp-49154
  - port: 49155
    name: tcp-49155
  - port: 49156
    name: tcp-49156
  - port: 49157
    name: tcp-49157
  - port: 49158
.
.
.
.... 200 more such ports

在应用此Yaml之后,将创建服务,但无法访问ip:port组合,并且出现连接拒绝错误。在进一步调查中,我发现iptables过滤器链KUBE-EXTERNAL-SERVICES中有一些REJECT条目,用于我暴露的端口。

IPTABLES拒绝规则

Chain KUBE-EXTERNAL-SERVICES (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere             /* default/multiport-server-large-port:tcp-49316 has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:31
184 reject-with icmp-port-unreachable
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere             /* default/multiport-server-large-port:tcp-49325 has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:31
225 reject-with icmp-port-unreachable
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere             /* default/multiport-server-large-port:tcp-49383 has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:32
620 reject-with icmp-port-unreachable
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere             /* default/multiport-server-large-port:tcp-49385 has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:30
107 reject-with icmp-port-unreachable
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere             /* default/multiport-server-large-port:tcp-49359 has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:31

我想了解:

  1. 为什么出现这些REJECT规则?
  2. 这是否不可能通过服务公开大量端口?
  3. 可以通过服务公开的端口数量是否有限制?

解决方法

当特定服务具有0个端点时,将插入REJECT。您的Service.spec中的选择器一定是错误的,否则您没有任何Pod正在运行