Kubernetes Networking Explained - Introduction
Kubernetes Networking Explained - Introduction
Kubernetes Networking
Explained: Introduction
Sounds like a lot of stuff, doesn’t it? It is. That’s why we decided
to create a series of articles explaining Kubernetes networking
from the bottom (container-to-container communication) to
the top (pod networking, services, DNS, and load balancing). In
the rst part of the series, we discuss container-to-container
and pod-to-pod networking. We demonstrate how Kubernetes
networking is different from the “normal” Docker approach,
what requirements for networking implementations it imposes,
and how it achieves a homogeneous networking system that
allows Pods communication across nodes. We think that by the
end of this article you’ll have a better understanding of
Privacy & Cookies Policy
https://supergiant.io/blog/kubernetes-networking-explained-introduction/ 2/13
23/04/2019 Kubernetes Networking Explained: Introduction
Fundamentals of Kubernetes
Networking
Kubernetes platform aims to simplify cluster networking by
creating a at network structure that frees users from setting
up dynamic port allocation to coordinate ports, designing
custom routing rules and sub-nets, and using Network Address
Translation (NAT) to move packets across different network
segments. To achieve this, Kubernetes prohibits networking
implementations involving any intentional network
segmentation policy. In other words, Kubernetes aims to keep
the networking architecture as simple as possible for the end
user. The Kubernetes platform sets the following networking
rules:
Kubernetes Solution
Kubernetes bypasses the above-mentioned limitation by
providing a shared network interface for containers. Using the
analogy from the Docker model, Kubernetes allows containers
to share a single veth interface like in the image below.
Tutorial
Now, let’s illustrate a possible scenario of the communication
between two containers running in a single pod. One of the
most common examples of the multi-container
communication via localhost is when one container like
Apache HTTP server or NGINX is con gured as a reverse proxy
that proxies requests to a web application running in another
container.
1 apiVersion: v1
2 kind: ConfigMap
3 metadata:
4 name: nginx-conf
5 data:
6 nginx.conf: |-
7 user nginx;
8 worker_processes 2;
9 error_log /var/log/nginx/error.log warn;
10 pid /var/run/nginx.pid;
11 events {
12 worker_connections 1024;
13 }
14 http {
15 sendfile on;
16 keepalive_timeout 65;
17 include /etc/nginx/conf.d/*.conf;
18 server {
19 listen 80 default_server;
20 location /ghost {
21 proxy_pass http://127.0.0.1:2368;
22 }
23 }
24 }
In brief, this Con gMap tells NGINX to proxy requests from its
default port localhost:80 to localhost:2368 on which the
Ghost is listening to requests.
1 apiVersion: apps/v1
2 kind: Deployment
3 metadata:
4 name: tut-deployment
5 labels:
6 app: tut
7 spec:
8 replicas: 1
9 selector:
10 matchLabels:
11 app: tut
12 template:
13 metadata:
14 labels:
15 app: tut
16 spec:
17 containers:
18 - name: ghost
19 image: ghost:latest
20 ports:
21 - containerPort: 2368
22 - name: nginx
23 image: nginx:alpine
24 ports:
25 - containerPort: 80
26 volumeMounts:
27 - name: proxy-config
28 mountPath: /etc/nginx/nginx.conf
29 subPath: nginx.conf
30 volumes:
31 - name: proxy-config
32 configMap:
33 name: nginx-conf
1 Name: tut-deployment
2 Namespace: default
3 Labels: app=tut
4 Selector: app=tut
5 Type: NodePort
6 IP: 10.3.208.190
7 Port: <unset> 80/TCP
8 NodePort: <unset> 30234/TCP
9 Endpoints: 10.2.6.6:80,10.2.6.7:80 Privacy & Cookies Policy
https://supergiant.io/blog/kubernetes-networking-explained-introduction/ 9/13
23/04/2019 Kubernetes Networking Explained: Introduction
That’s it! Now you see how containers can easily communicate
via localhost using built-in Pod’s virtual network. As such, a
container-to-container networking is a building block of the
next layer, which is a pod-to-pod networking discussed in the
next section.
From Container-to-Container
to Pod-to-Pod Communication
One of the most exciting features in Kubernetes is that pods
and containers within pods can communicate with each other
even if they land on different nodes. This feature is something
that is not implemented in Docker by default (Note: Docker
supports multi-host connectivity as a custom solution available
via overlay driver). Before delving deeper into how
Kubernetes implements pod-to-pod networking, let’s rst
discuss how networking works on a pod level.
Conclusion
In this article, we covered two basic components of the
Kubernetes networking architecture: container-to-container
networking and pod-to-pod networking. We have seen that
Kubernetes uses overlay networking to create a at network
structure where containers and pods can communicate with
each other across nodes. All routing rules and IP namespaces
are managed by Kubernetes by default, so there is no need to
bother creating subnets and using dynamic port allocation. In
fact, there are several out-of-the-box overlay network
implementations to get you started. Kubernetes networking
enables an easy migration of applications from VMs to pods,
which can be treated as “virtual hosts” with the functionality of
VMs but with an added bene t of container isolation and
microservices architecture. In our following tutorial, we discuss
the next layer of the Kubernetes networking: services, which are
abstractions that implement microservices and service
Privacy & Cookies Policy
https://supergiant.io/blog/kubernetes-networking-explained-introduction/ 12/13
23/04/2019 Kubernetes Networking Explained: Introduction
SUPPORT
Pricing
Customer Portal
TOOLKIT
Supergiant Repo
Capacity
Control
Analyze
COMPANY
About Us
Contact Us
Privacy Policy
Support Policy