Skip to content

Commit b930af1

Browse files
committed
Expand section about network
1 parent 1412675 commit b930af1

File tree

3 files changed

+133
-16
lines changed

3 files changed

+133
-16
lines changed

source/examples/valkey0/play.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ metadata:
44
name: client-entrypoint
55
data:
66
entrypoint.sh: |
7-
valkey-cli set counter 0
7+
valkey-cli -h server set counter 0
88
while [ -z "" ]
99
do
10-
valkey-cli incr counter
10+
valkey-cli -h server incr counter
1111
sleep 5s
1212
done
1313
---

source/examples/valkey1/play.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: client-entrypoint
5+
data:
6+
entrypoint.sh: |
7+
valkey-cli -h valkey1-server set counter 0
8+
while [ -z "" ]
9+
do
10+
valkey-cli -h valkey1-server incr counter
11+
sleep 5s
12+
done
13+
---
14+
apiVersion: v1
15+
kind: Pod
16+
metadata:
17+
labels:
18+
app: valkey
19+
name: valkey1-server
20+
spec:
21+
containers:
22+
- name: server
23+
image: docker.io/valkey/valkey:8.0.2-alpine
24+
---
25+
apiVersion: v1
26+
kind: Pod
27+
metadata:
28+
labels:
29+
app: valkey
30+
name: valkey1-client
31+
spec:
32+
containers:
33+
- name: client
34+
image: docker.io/valkey/valkey:8.0.2-alpine
35+
command:
36+
- /bin/sh
37+
- /opt/entrypoint.sh
38+
volumeMounts:
39+
- mountPath: /opt
40+
name: client-entrypoint-volume
41+
volumes:
42+
- configMap:
43+
name: client-entrypoint
44+
items:
45+
- key: "entrypoint.sh"
46+
path: "entrypoint.sh"
47+
name: client-entrypoint-volume

source/k8s-network.rst

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
Pod and Network
22
===============
33

4-
Normally, we want for one container to access the program running on another container.
4+
Normally, we want for one container to access the program running on another container. Two scenarios are possible: containers run on the same pod or containers run on different pods.
55

6-
.. mermaid::
7-
:align: center
8-
:alt: Diagram of network.
9-
:caption: Diagram of network.
6+
Containers on the same Pod
7+
--------------------------
108

11-
graph LR;
12-
browser[Web browser] --> flask[Flask];
13-
flask .-> postgres[PostgreSQL];
9+
.. mermaid::
10+
:align: center
11+
:alt: Diagram of containers running on the same pod.
12+
:caption: Diagram of containers running on the same pod.
1413

14+
flowchart
1515
subgraph pod[Pod]
1616
flask
1717
postgres
1818
end
1919

20+
subgraph network[Network]
21+
pod
22+
end
23+
2024
subgraph host[Host]
2125
browser
26+
network
27+
pod
2228
end
2329

24-
The container can be reached by another container if they are part of the same pod of if they are part of the same network.
30+
browser[Web browser] --> flask[Flask];
31+
flask .-> postgres[PostgreSQL];
2532

26-
Containers in the same Pod
27-
--------------------------
33+
classDef classPod fill:lightblue,stroke:blue
34+
class pod classPod;
35+
36+
classDef classNetwork stroke:black,stroke-dasharray: 5 5
37+
class network classNetwork;
2838

29-
Containers in the same pod share the IP addresses, MAC addresses and port mappings. This allows the container to be reached by another container using ``localhost:port``.
39+
Containers in the same pod share the IP addresses, MAC addresses and port mappings. This allows the container to be reached by another container using ``localhost`` or the name of the container.
3040

3141
Example
3242
^^^^^^^
@@ -43,5 +53,65 @@ running ::
4353

4454
creates a pod named ``valkey0`` with a container named ``server`` running the `Valkey <https://valkey.io/>`_ server and another container named ``client`` running a small Bash script that increases a counter every 5 seconds.
4555

46-
Containers in the same Network
47-
------------------------------
56+
Containers on different pods
57+
----------------------------
58+
59+
.. mermaid::
60+
:align: center
61+
:alt: Diagram of containers running on different pods.
62+
:caption: Diagram of containers running on different pods.
63+
64+
flowchart
65+
subgraph pod1[Pod 1]
66+
flask
67+
end
68+
69+
subgraph pod2[Pod 2]
70+
postgres
71+
end
72+
73+
subgraph network[Network]
74+
pod1
75+
pod2
76+
end
77+
78+
subgraph host[Host]
79+
browser
80+
network
81+
pod1
82+
pod2
83+
end
84+
85+
browser[Web browser] --> flask[Flask];
86+
flask .-> postgres[PostgreSQL];
87+
88+
classDef classPod fill:lightblue,stroke:blue
89+
class pod1,pod2 classPod;
90+
91+
classDef classNetwork stroke:black,stroke-dasharray: 5 5
92+
class network classNetwork;
93+
94+
The container can be reached by another container if they are part of the same pod of if they are part of the same network.
95+
96+
Example
97+
^^^^^^^
98+
99+
.. important::
100+
101+
When no network option is specified and host network mode is not configured in the YAML file, a new network stack is created and pods are attached to it making possible pod to pod communication.
102+
103+
First, create a new network by running ::
104+
105+
podman network valkey1
106+
107+
Given the following Kubernetes manifest file
108+
109+
.. literalinclude:: examples/valkey1/play.yml
110+
:language: yaml
111+
:caption: play.yml
112+
113+
running ::
114+
115+
podman kube play --net valkey1 play.yml
116+
117+
creates a pod named ``valkey1-server`` connected to the network ``valkey1`` with a container named ``server`` running the `Valkey <https://valkey.io/>`_ server and another pod named ``valkey1-client`` connected to the network ``valkey1`` with a container named ``client`` running a small Bash script that increases a counter every 5 seconds.

0 commit comments

Comments
 (0)