Skip to content

Commit 5c9bb88

Browse files
danwinshipTim Bannister
andcommitted
Rewrite "The Kubernetes network model"
Co-authored-by: Tim Bannister <[email protected]>
1 parent e9e80dd commit 5c9bb88

File tree

1 file changed

+97
-52
lines changed
  • content/en/docs/concepts/services-networking

1 file changed

+97
-52
lines changed

content/en/docs/concepts/services-networking/_index.md

Lines changed: 97 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,103 @@ description: >
77

88
## The Kubernetes network model
99

10-
Every [`Pod`](/docs/concepts/workloads/pods/) in a cluster gets its own unique cluster-wide IP address
11-
(one address per IP address family).
12-
This means you do not need to explicitly create links between `Pods` and you
13-
almost never need to deal with mapping container ports to host ports.
14-
This creates a clean, backwards-compatible model where `Pods` can be treated
15-
much like VMs or physical hosts from the perspectives of port allocation,
16-
naming, service discovery, [load balancing](/docs/concepts/services-networking/ingress/#load-balancing),
17-
application configuration, and migration.
18-
19-
Kubernetes imposes the following fundamental requirements on any networking
20-
implementation (barring any intentional network segmentation policies):
21-
22-
* pods can communicate with all other pods on any other [node](/docs/concepts/architecture/nodes/)
23-
without NAT
24-
* agents on a node (e.g. system daemons, kubelet) can communicate with all
25-
pods on that node
26-
27-
{{< note >}}
28-
For those platforms that support `Pods` running in the host network (such as Linux), when pods are attached to the host network of a node they can still communicate with all pods on all nodes without NAT.
29-
{{< /note >}}
30-
31-
This model is not only less complex overall, but it is principally compatible
32-
with the desire for Kubernetes to enable low-friction porting of apps from VMs
33-
to containers. If your job previously ran in a VM, your VM had an IP and could
34-
talk to other VMs in your project. This is the same basic model.
35-
36-
Kubernetes IP addresses exist at the `Pod` scope - containers within a `Pod`
37-
share their network namespaces - including their IP address and MAC address.
38-
This means that containers within a `Pod` can all reach each other's ports on
39-
`localhost`. This also means that containers within a `Pod` must coordinate port
40-
usage, but this is no different from processes in a VM. This is called the
41-
"IP-per-pod" model.
42-
43-
How this is implemented is a detail of the particular container runtime in use.
44-
45-
It is possible to request ports on the `Node` itself which forward to your `Pod`
46-
(called host ports), but this is a very niche operation. How that forwarding is
47-
implemented is also a detail of the container runtime. The `Pod` itself is
48-
blind to the existence or non-existence of host ports.
49-
50-
Kubernetes networking addresses four concerns:
51-
- Containers within a Pod [use networking to communicate](/docs/concepts/services-networking/dns-pod-service/) via loopback.
52-
- Cluster networking provides communication between different Pods.
53-
- The [Service](/docs/concepts/services-networking/service/) API lets you
54-
[expose an application running in Pods](/docs/tutorials/services/connect-applications-service/)
55-
to be reachable from outside your cluster.
56-
- [Ingress](/docs/concepts/services-networking/ingress/) provides extra functionality
57-
specifically for exposing HTTP applications, websites and APIs.
58-
- [Gateway API](/docs/concepts/services-networking/gateway/) is an {{<glossary_tooltip text="add-on" term_id="addons">}}
59-
that provides an expressive, extensible, and role-oriented family of API kinds for modeling service networking.
60-
- You can also use Services to
61-
[publish services only for consumption inside your cluster](/docs/concepts/services-networking/service-traffic-policy/).
10+
The Kubernetes network model is built out of several pieces:
11+
12+
* Each [Pod](/docs/concepts/workloads/pods/) in a cluster gets its
13+
own unique cluster-wide IP address.
14+
15+
* A pod has its own private network namespace which is shared by
16+
all of the containers within the pod. Processes running in
17+
different containers in the same pod can communicate with each
18+
other over `localhost`.
19+
20+
* The _pod network_ (also called a cluster network) handles communication
21+
between pods. It ensures that (barring intentional network
22+
segmentation):
23+
24+
* All pods can communicate with all other pods, whether they are
25+
on the same [node](/docs/concepts/architecture/nodes/) or on
26+
different nodes. Pods can communicate with each other
27+
directly, without the use of proxies or address translation
28+
(NAT).
29+
30+
* (On Windows, this rule does not apply to host-network pods.)
31+
32+
* Agents on a node (such as system daemons, or kubelet) can
33+
communicate with all pods on that node.
34+
35+
* The [Service](/docs/concepts/services-networking/service/) API
36+
lets you provide a stable (long lived) IP address or hostname for a service implemented
37+
by one or more backend pods, where the individual pods making up
38+
the service can change over time.
39+
40+
* Kubernetes automatically manages
41+
[EndpointSlice](/docs/concepts/services-networking/endpoint-slices/)
42+
objects to provide information about the pods currently
43+
backing a Service.
44+
45+
* A service proxy implementation monitors the `Service` and
46+
`EndpointSlice` objects, and programs the data plane to route
47+
service traffic to its backends, by using operating system or
48+
cloud provider APIs to intercept or rewrite packets.
49+
50+
* The [Gateway](/docs/concepts/services-networking/gateway/) API
51+
(or its predecessor,
52+
[Ingress](/docs/concepts/services-networking/ingress/)) allows
53+
you to make Services accessible to clients that are outside the cluster.
54+
55+
* A simpler, but less-configurable, mechanism for cluster
56+
ingress is available via the Service API's [`type:
57+
LoadBalancer`](/docs/concepts/services-networking/service/#loadbalancer),
58+
when using a supported {{< glossary_tooltip term_id="cloud-provider">}}.
59+
60+
* [NetworkPolicy](/docs/concepts/services-networking/network-policies) is a built-in
61+
Kubernetes API that
62+
allows you to control traffic between pods, or between pods and
63+
the outside world.
64+
65+
In older container systems, there was no automatic connectivity
66+
between containers on different hosts, and so it was often necessary
67+
to explicitly create links between containers, or to map container
68+
ports to host ports to make them reachable by containers on other
69+
hosts. This is not needed in Kubernetes; Kubernetes's model is that
70+
pods can be treated much like VMs or physical hosts from the
71+
perspectives of port allocation, naming, service discovery, load
72+
balancing, application configuration, and migration.
73+
74+
Only a few parts of this model are implemented by Kubernetes itself.
75+
For the other parts, Kubernetes defines the APIs, but the
76+
corresponding functionality is provided by external components, some
77+
of which are optional:
78+
79+
* Pod network namespace setup is handled by system-level software
80+
implementing the [Container Runtime
81+
Interface](/docs/concepts/architecture/cri.md).
82+
83+
* The pod network itself is managed by a [pod network
84+
implementation](/docs/concepts/cluster-administration/addons/#networking-and-network-policy).
85+
On Linux, most container runtimes use the
86+
{{< glossary_tooltip text="Container Networking Interface (CNI)" term_id="cni" >}}
87+
to interact with the pod network implementation, so these
88+
implementations are often called _CNI plugins_.
89+
90+
* Kubernetes provides a default implementation of service proxying,
91+
called {{< glossary_tooltip term_id="kube-proxy">}}, but some pod
92+
network implementations instead use their own service proxy that
93+
is more tightly integrated with the rest of the implementation.
94+
95+
* NetworkPolicy is generally also implemented by the pod network
96+
implementation. (Some simpler pod network implementations don't
97+
implement NetworkPolicy, or an administrator may choose to
98+
configure the pod network without NetworkPolicy support. In these
99+
cases, the API will still be present, but it will have no effect.)
100+
101+
* There are many [implementations of the Gateway
102+
API](https://gateway-api.sigs.k8s.io/implementations/), some of
103+
which are specific to particular cloud environments, some more
104+
focused on "bare metal" environments, and others more generic.
105+
106+
## {{% heading "whatsnext" %}}
62107

63108
The [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial lets you learn about Services and Kubernetes networking with a hands-on example.
64109

0 commit comments

Comments
 (0)