大网数据广告活动
服务器运维问答

Kubernetes: relation between Service IP's and pod IP's

· 52CE 我爱测

I'm trying to understand a bit more about Kubernetes networking. That's why I've deployed a cluster in google cloud and checked the networking: gcloud container clusters describe cluster0 | grep -i cidr clusterIpv4Cidr: 10.20.0.0…

问题原文

原帖链接 · DenCowboy · CC BY-SA 4.0

I'm trying to understand a bit more about Kubernetes networking. That's why I've deployed a cluster in google cloud and checked the networking:

gcloud container clusters describe cluster0 | grep -i cidr

clusterIpv4Cidr: 10.20.0.0/14        # --cluster-cidr
nodeIpv4CidrSize: 24
servicesIpv4Cidr: 10.23.240.0/20     # --service-cluster-ip-range

So the first is for pod IPs:

First IP: 10.20.0.1
Last IP: 10.23.255.254

Service

First IP: 10.23.240.1
Last IP: 10.23.255.254

Is it always like this that the pod range contains the service IP range? Are they using the same network layer?

已采纳解答

原帖链接 · d0bry · CC BY-SA 3.0

It is a long story how Kubernetes network is made...

Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Every pod gets its own IP address so you do not need to explicitly create links between pods and you almost never need to deal with mapping container ports to host ports. This creates a clean, backwards-compatible model where pods can be treated much like VMs or physical hosts from the perspectives of port allocation, naming, service discovery, load balancing, application configuration, and migration.

Kubernetes use both private and public accessible IP addresses. Public IP addresses are not mentioned at this moment.

Kubernetes uses private pool of addresses to provide communication inside a cluster. Every pod and service has a private IP address. Services in Kubernetes are virtual - they are created by NAT, and iptables creates port redirection from addressed service to pods.

Basic rules of the communication inside of the cluster:

  • all containers can communicate with all other containers without NAT
  • all nodes can communicate with all containers (and vice-versa) without NAT the IP that a container sees itself as is the same IP that others see it as

Regarding your question: official Kubernetes network documentation states:

--service-cluster-ip-range ipNet -  A CIDR notation IP range from which to assign service cluster IPs. This must not overlap with any IP ranges assigned to nodes for pods.

So, is not recommended to have service IP in the same range that is used by pods.

I highly recommend watching video about Kubernetes networking or looking at illustrated guide.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。