You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
5
5
6
-
.. mermaid::
7
-
:align: center
8
-
:alt: Diagram of network.
9
-
:caption: Diagram of network.
6
+
Containers on the same Pod
7
+
--------------------------
10
8
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.
14
13
14
+
flowchart
15
15
subgraph pod[Pod]
16
16
flask
17
17
postgres
18
18
end
19
19
20
+
subgraph network[Network]
21
+
pod
22
+
end
23
+
20
24
subgraph host[Host]
21
25
browser
26
+
network
27
+
pod
22
28
end
23
29
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.
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.
30
40
31
41
Example
32
42
^^^^^^^
@@ -43,5 +53,65 @@ running ::
43
53
44
54
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.
45
55
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.
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