<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title>SysAdmin Journal · Networking</title>
        <link>https://sysadmin-journal.com/tag/networking</link>
        <description>Posts tagged with Networking</description>
        <language>en</language>
        <lastBuildDate>Tue, 05 Nov 2019 12:19:18 +0000</lastBuildDate>
        <atom:link href="https://sysadmin-journal.com/tag/networking/rss" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        <item>
            <title>Understand networking in Podman</title>
            <link>https://sysadmin-journal.com/understand-podman-networking</link>
            <guid isPermaLink="true">https://sysadmin-journal.com/understand-podman-networking</guid>
            <pubDate>Tue, 05 Nov 2019 12:19:18 +0000</pubDate>
            <dc:creator>Ish Sookun</dc:creator>
            <category>Containers</category>
            <category>Networking</category>
            <category>openSUSE</category>
            <description>I received a message on Twitter on 17 October from a fellow who attended the openSUSE Asia Summit 2019. Strangely, I didn&#039;t get any notification about it and it&#039;s only today that I read the message. He also attended my workshop on openSUSE MicroOS and had some questions regarding inter-Pod...</description>
            <content:encoded><![CDATA[<p>I received a message on Twitter on 17 October from a fellow who attended the <a href="https://hacklog.in/opensuse-asia-summit/"><strong>openSUSE Asia Summit 2019</strong></a>. Strangely, I didn't get any notification about it and it's only today that I read the message. He also attended my workshop on <a href="https://speakerdeck.com/ishwon/opensuse-microos-0c74315f-e2a6-4699-8c57-ec215c414edc"><strong>openSUSE MicroOS</strong></a> and had some questions regarding inter-Pod communication.</p><p>As a quick response, I explained him very breifly about "container networking" and pointed him to the <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/network-overview#ip-allocation"><strong>Kubernetes documentation</strong></a> on IP allocation. I do realize though, that most of the times, documenation can be lengthy and {boring}, and that you would just want a simple article or blog post that clears your doubts.</p><h2 id="tell-me-about-podman-networks">Tell me about Podman networks</h2><p>Rootless containers (i.e containers started using Podman as a regular user) do not obtain an IP address. Podman uses <a href="https://github.com/rootless-containers/slirp4netns"><strong>slirp4netns</strong></a> to allow Internet connectivity inside the container.</p><p>Communication with a rootless container is achieved by mapping the container ports to the host, e.g using <strong>-p 8080:80</strong> to map a webserver port 80 to the host on port port 8080.</p><pre><code>$ podman run -dt --name webserver -p 8080:80 nginx
$ curl http://localhost:8080</code></pre><p>Therefore, two rootless containers can communicate over their published ports on the host. Let's experiment this by starting an openSUSE Leap container and installing the telnet package. </p><pre><code>$ podman run -dt --name leap leap
$ podman exec -it leap bash

4a0f95e011b9:/ # zypper in telnet</code></pre><p>We run <strong>ip a s</strong> on the host to find its IP address. Say the IP address is 192.168.100.8. Now, from within Leap container let's telnet port 8080 over the host IP.</p><pre><code>4a0f95e011b9:/ # telnet 192.168.100.10 8080
Trying 192.168.100.10...
Connected to 192.168.100.10.
Escape character is '^]'.</code></pre><p>The connection went through successfully, meaning from the Leap container we've been able to access the Nginx container through it's mapped port on the host.</p><p>This same experiment can be repeated using two different pods, say you have a pod that contains your web services and another pod that contains your databases.</p><pre><code>$ podman pod create --name webservice -p 8080:80
$ podman run -dt --name webserver --pod webservice nginx

$ podman pod create --name db -p 3306:3306
$ podman run -dt --name mariadb --pod db -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" mariadb</code></pre><p>The Nginx container will be able to reach the MariaDB database over <strong>192.168.100.10:3306</strong> as the same port is mapped on the host.</p><p>Ideally, these two containers could have been created in the same pod and therefore share the same network space. Then, the Nginx container would reach the database over <strong>localhost:3306</strong> easily.</p><p>I used the above Nginx/MariaDB example to explain rootless inter-Pod communication, which was the question that was asked to me initially.</p><h2 id="what-about-rootfull-containers">What about rootfull containers?</h2><p>Rootfull containers are those that are created using Podman with root privileges, either by the root user itself or using sudo privilege.</p><p>Containers created using Podman with root privileges obtain an IP address. Podman then uses the <a href="https://github.com/containernetworking/cni"><strong>Container Network Interfec (CNI)</strong></a> instead of slirp4netns for networking provisioning.</p><p>Details about the network subnet is found in the CNI config file.</p><pre><code>$ cat /etc/cni/net.d/87-podman-bridge.conflist

{
    "cniVersion": "0.3.0",
    "name": "podman",
    "plugins": [
      {
        "type": "bridge",
        "bridge": "cni0",
        "isGateway": true,
        "ipMasq": true,
        "ipam": {
            "type": "host-local",
            "subnet": "10.88.0.0/16",
            "routes": [
                { "dst": "0.0.0.0/0" }
            ]
        }
      },
      {
        "type": "portmap",
        "capabilities": {
          "portMappings": true
        }
      }
    ]
}</code></pre><p>So, let's start a container with root privileges and see.</p><pre><code>$ sudo podman run -dt --name db postgres

$ sudo podman inspect -f "{{.NetworkSettings.IPAddress}}" db
10.88.0.30</code></pre><p>The <strong>podman inspect ...</strong> command returns the container's IP address and the same is ranged within the subnet specified in the CNI config. The PostgreSQL database can be accessed over <strong>10.88.0.30:5432</strong> from the host or from within any other container started using root privileges.</p><pre><code>$ telnet 10.88.0.30 5432
Trying 10.88.0.30...
Connected to 10.88.0.30.
Escape character is '^]'.</code></pre>]]></content:encoded>
        </item>
    </channel>
</rss>
