Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

hostname points to the name of the infra container instead to hostname of the pod itself #11

Closed
abalage opened this issue Jan 29, 2020 · 9 comments

Comments

@abalage
Copy link

abalage commented Jan 29, 2020

Hi,

I am having an issue with name resolution not working with pod names.
I would like to achieve pod-to-pod communication via hostnames / DNS of pods.

I create a pod for each different systems I may use. Each pods contain different number of containers. The plugin dnsname is configured for the default network.

The very basic setup I'd like to achieve can be seen on the picture below.

DSC_0084

As all the pods are attached to the same network (cni-podman0) IP connectivity is not a problem.
Checking the hosts file within containers of the same pod I see that they aware of the hostname of the pod as well its IP address.
However the DNS service running in the same network is only resolving the IP addresses of infra containers. The problem with that is their name is auto generated from the ID of the pod. I cannot rely on them. I would rather like to see the --name or --hostname of the pods bounded to the IP of infra contrainer by dnsname.

Checking the source code I could find this part.

type podname struct {
types.CommonArgs
K8S_POD_NAME types.UnmarshallableString `json:"podname,omitempty"`
}

But I do not know whether 'podname' should point to the name of the pod (sounds reasonable) of to the name of the container?

# podman network inspect podman
[
        {
                "cniVersion": "0.4.0",
                "name": "podman",
                "plugins": [
                        {
                                "bridge": "cni-podman0",
                                "ipMasq": true,
                                "ipam": {
                                        "ranges": [
                                                [
                                                        {
                                                                "gateway": "10.88.0.1",
                                                                "subnet": "10.88.0.0/16"
                                                        }
                                                ]
                                        ],
                                        "routes": [
                                                {
                                                        "dst": "0.0.0.0/0"
                                                }
                                        ],
                                        "type": "host-local"
                                },
                                "isGateway": true,
                                "type": "bridge"
                        },
                        {
                                "domainName": "podman.local",
                                "type": "dnsname"
                        },
                        {
                                "capabilities": {
                                        "portMappings": true
                                },
                                "type": "portmap"
                        },
                        {
                                "backend": "firewalld",
                                "type": "firewall"
                        }
                ]
        }
]

# podman ps -ap
CONTAINER ID  IMAGE                                                COMMAND               CREATED      STATUS          PORTS                                                   NAMES               POD           POD NAME
bc79e85d737f  docker.io/library/nginx:1.16                         nginx -g daemon o...  3 hours ago  Up 3 hours ago  192.168.122.253:80->80/tcp                              proxy               e59ccfa83aa6  reverse_proxy
f89ad7e8e4cd  registry.opensuse.org/kubic/pause:3.1                                      3 hours ago  Up 3 hours ago  192.168.122.253:80->80/tcp                              e59ccfa83aa6-infra  e59ccfa83aa6  reverse_proxy
29b35a360e91  docker.io/library/mariadb:10.4                       mysqld                3 hours ago  Up 3 hours ago  0.0.0.0:3306->3306/tcp                                  mariadb             c7090bdc990d  mysql
32e01f41626a  registry.opensuse.org/kubic/pause:3.1                                      3 hours ago  Up 3 hours ago  0.0.0.0:3306->3306/tcp                                  c7090bdc990d-infra  c7090bdc990d  mysql
048bb0b9fe83  docker.io/library/redis:5                            redis-server          3 hours ago  Up 3 hours ago  0.0.0.0:8080->80/tcp                                    nextcloud-redis     fe69e1d9a88e  nextcloud
70cc7e3d0bb3  docker.io/library/nginx:1.16                         nginx -g daemon o...  3 hours ago  Up 3 hours ago  0.0.0.0:8080->80/tcp                                    nextcloud-www       fe69e1d9a88e  nextcloud
ebc69be64be9  localhost/balage/php72-fpm-opensuse:latest           php-fpm -c /etc/p...  3 hours ago  Up 3 hours ago  0.0.0.0:8080->80/tcp                                    nextcloud-php       fe69e1d9a88e  nextcloud
fbdd9fa5baad  registry.opensuse.org/kubic/pause:3.1                                      3 hours ago  Up 3 hours ago  0.0.0.0:8080->80/tcp                                    fe69e1d9a88e-infra  fe69e1d9a88e  nextcloud
b27d58d62133  docker.elastic.co/kibana/kibana:7.4.2                /usr/local/bin/ki...  3 hours ago  Up 3 hours ago  0.0.0.0:5601->5601/tcp, 192.168.122.253:9200->9200/tcp  kibana              03e5e1a02d0f  elk
db3a7c79d3bf  docker.elastic.co/elasticsearch/elasticsearch:7.4.2  eswrapper             3 hours ago  Up 3 hours ago  0.0.0.0:5601->5601/tcp, 192.168.122.253:9200->9200/tcp  elasticsearch       03e5e1a02d0f  elk
4b9d202aa91e  registry.opensuse.org/kubic/pause:3.1

# cat /run/containers/cni/dnsname/podman/addnhosts
10.88.0.148     03e5e1a02d0f-infra
10.88.0.149     fe69e1d9a88e-infra
10.88.0.150     c7090bdc990d-infra
10.88.0.151     e59ccfa83aa6-infra

# podman exec -ti nextcloud-www cat /etc/hosts
127.0.0.1       localhost
...
10.88.0.149     nextcloud

Here are some details you may find useful.

# podman --version
podman version 1.7.0

# podman info 
host:
  BuildahVersion: 1.12.0
  CgroupVersion: v1
  Conmon:
    package: conmon-2.0.9-lp151.19.1.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.9, commit: unknown'
  Distribution:
    distribution: '"opensuse-leap"'
    version: "15.1"
  MemFree: 4509601792
  MemTotal: 8340729856
  OCIRuntime:
    name: runc
    package: runc-1.0.0~rc6-lp151.1.2.x86_64
    path: /usr/sbin/runc
    version: |-
      runc version 1.0.0-rc6
      spec: 1.0.1-dev
  SwapFree: 0
  SwapTotal: 0
  arch: amd64
  cpus: 2
  eventlogger: file
  hostname: linux-thwt
  kernel: 5.4.14-1.gfc4ea7a-default
  os: linux
  rootless: false
  uptime: 3h 45m 32.16s (Approximately 0.12 days)
registries:
  search:
  - docker.io
store:
  ConfigFile: /etc/containers/storage.conf
  ContainerStore:
    number: 11
  GraphDriverName: overlay
  GraphOptions: {}
  GraphRoot: /var/lib/containers/storage
  GraphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  ImageStore:
    number: 9
  RunRoot: /var/run/containers/storage
  VolumePath: /var/lib/containers/storage/volumes
@abalage
Copy link
Author

abalage commented Jan 29, 2020

tl;dr.

I would need a 'poor man's' service discovery. Find published ports of pods on the same network by using the name of the pods. And not by the name of the infra container of a pod.

@baude
Copy link
Member

baude commented Jan 29, 2020

@abalage name resolution does is not supported yet for pods ... BUT I am currently working on it

@abalage
Copy link
Author

abalage commented Jan 29, 2020

Great to hear. I am happy to test any release you may have.

@ecks
Copy link

ecks commented Feb 19, 2020

I would be interested in this feature as well, since I would like to use "podman play kube" as a way to import podman configurations. When you do that, everything gets imported as a pod, so my workaround has been to manually add the container name entries to addnhosts file.

Would this be the correct place to track the progress?

@mi-hol
Copy link

mi-hol commented Jul 13, 2020

@baude any news re 'currently working on it'?

@baude
Copy link
Member

baude commented Jul 16, 2020

@mi-hol sorry! yes, name resolution for pods works like containers now. Remember all containers in a podman pod share the same network namespace by default. So you can set the hostname with podman pod create --hostname.

@mi-hol
Copy link

mi-hol commented Jul 21, 2020

@baude , would your answer mean that this issue should be closed?

@baude
Copy link
Member

baude commented Aug 3, 2020

I think so but always nice that the reported concurs... closing. Please re-open or open a new issue if you disagree.

@baude baude closed this as completed Aug 3, 2020
@WolfangAukang
Copy link

Hello @baude, so a quick question about using this feature. I am running the following:

podman pod create --name pod_db --network foobar --hostname db
podman run -d --pod pod_db --name mariadb -e MYSQL_RANDOM_ROOT_PASSWORD=1 mariadb:10.4
podman pod create --name pod_front --network foobar --hostname frontend
podman run -it --pod pod_front busybox sh

foobar is a network created according to the guide and it runs as expected between pods. But if I try to run ping db or telnet db 3306, it does not get any answers. Am I doing something wrong?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants