Skip to content

Commit 653f2f2

Browse files
committed
Review k8s-port
1 parent 889dcb5 commit 653f2f2

File tree

1 file changed

+135
-2
lines changed

1 file changed

+135
-2
lines changed

source/k8s-port.rst

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,80 @@ Normally, we want to access the program running on the container from the host.
3131
classDef classNetwork stroke:black,stroke-dasharray: 5 5
3232
class network classNetwork;
3333

34+
.. important::
35+
36+
Because Windows and macOS cannot run containers natively, the network is more complex when working on Windows and macOS.
37+
38+
.. mermaid::
39+
:align: center
40+
:alt: Diagram of access container from Windows or macOS.
41+
:caption: Diagram of access container from Windows or macOS.
42+
43+
flowchart
44+
subgraph pod[Pod]
45+
nginx
46+
end
47+
48+
subgraph network[Network]
49+
pod
50+
end
51+
52+
subgraph podman-machine[Podman Machine]
53+
network
54+
end
55+
56+
subgraph host[Windows or macOS]
57+
browser
58+
podman-machine
59+
end
60+
61+
browser[Web browser] --> nginx[NGINX];
62+
63+
classDef classPod fill:lightblue,stroke:blue
64+
class pod classPod;
65+
66+
classDef classNetwork fill:orange,stroke:darkorange,stroke:black,stroke-dasharray: 5 5
67+
class network classNetwork;
68+
69+
classDef classPodmanMachine fill:orange,stroke:darkorange
70+
class podman-machine classPodmanMachine;
71+
72+
It is easy to think that the container is hosted in a different device on the `local area network (LAN) <https://en.wikipedia.org/wiki/Local_area_network>`_.
73+
74+
.. mermaid::
75+
:align: center
76+
:alt: Diagram of access container from Windows or macOS over LAN.
77+
:caption: Diagram of access container from Windows or macOS over LAN.
78+
79+
flowchart LR
80+
subgraph pod[Pod]
81+
nginx
82+
end
83+
84+
subgraph network[Network]
85+
pod
86+
end
87+
88+
subgraph podman-machine[Podman Machine]
89+
network
90+
end
91+
92+
subgraph host[Windows or macOS]
93+
browser
94+
end
95+
96+
browser[Web browser] --> router;
97+
router --> nginx[NGINX];
98+
99+
classDef classPod fill:lightblue,stroke:blue
100+
class pod classPod;
101+
102+
classDef classNetwork fill:orange,stroke:darkorange,stroke:black,stroke-dasharray: 5 5
103+
class network classNetwork;
104+
105+
classDef classPodmanMachine fill:orange,stroke:darkorange
106+
class podman-machine classPodmanMachine;
107+
34108
The container can expose some ports (for example, the port 80 to receive HTTP requests) and the exposed port can be mapped to a port in the host. This way, a request to the port in the host is passed to the container.
35109

36110
.. important::
@@ -39,13 +113,13 @@ The container can expose some ports (for example, the port 80 to receive HTTP re
39113

40114
.. code:: bash
41115
42-
sysctl net.ipv4.ip_unprivileged_port_start=80
116+
sudo sysctl net.ipv4.ip_unprivileged_port_start=80
43117
44118
or **permanentily** make a specific port (for example, port 80) not privileged using
45119

46120
.. code:: bash
47121
48-
sysctl -w net.ipv4.ip_unprivileged_port_start=80
122+
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
49123
50124
Example
51125
-------
@@ -95,3 +169,62 @@ that is expected to return ::
95169
<p><em>Thank you for using nginx.</em></p>
96170
</body>
97171
</html>
172+
173+
Windows Subsystem for Linux (WLS)
174+
---------------------------------
175+
176+
Windows 10
177+
^^^^^^^^^^
178+
179+
WSL uses a `NAT (Network Address Translation) <https://learn.microsoft.com/en-us/windows/wsl/networking#default-networking-mode-nat>`_ based architecture for networking. This allows the use of the `loopback <https://en.wikipedia.org/wiki/Loopback>`_ address from Windows to access the machine running Podman, for example
180+
181+
.. code:: powershell
182+
183+
curl.exe http://localhost:8080
184+
185+
or
186+
187+
.. code:: powershell
188+
189+
curl.exe http://127.0.0.1:8080
190+
191+
or
192+
193+
.. code:: powershell
194+
195+
curl.exe http://[::1]:8080
196+
197+
.. warning::
198+
199+
``curl.exe http://127.0.0.1:8080`` should work but it fails when tested.
200+
201+
It is also possible to use the IP address in the local area network (LAN) of the machine running Podman. First, discover the IP address.
202+
203+
.. code:: powershell
204+
205+
wsl.exe hostname -I
206+
207+
::
208+
209+
172.25.11.50
210+
211+
.. important::
212+
213+
The IP address might change when the WSL machine restarts.
214+
215+
.. note::
216+
217+
The IP address can be used in ``C:\Windows\System32\drivers\etc\hosts``.
218+
219+
And use the IP address
220+
221+
.. code:: powershell
222+
223+
curl.exe http://172.25.11.50:8080
224+
225+
Windows 11
226+
^^^^^^^^^^
227+
228+
.. important::
229+
230+
The new `Mirrored mode networking <https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking>`_ is available on Windows 11 22H2 and higher.

0 commit comments

Comments
 (0)