AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 703721
Accepted
Chuck
Chuck
Asked: 2022-05-25 13:17:40 +0800 CST2022-05-25 13:17:40 +0800 CST 2022-05-25 13:17:40 +0800 CST

podman play kube --network 没有正确连接网络

  • 772

我在 RHEL8.6 上使用 podman 来部署一个由两个容器组成的 pod,zabbix-server 和 postgres-server。为了部署容器,podman play kube在 .yaml 文件上使用以导入和运行 pod 配置。这是一个无根设置。

容器需要使用 DNS 通过内部网络进行通信。我podman create network mon用来创建一个名为“mon”的桥接网络,它启用了 DNS。

使用podman play kube monitoring.yaml --network mon,容器无法通过 DNS 相互通信。我通过手动创建 pod 和容器来测试设置,而不使用 podman play kube。在手动设置中,pod 中的容器能够使用 DNS 找到彼此。

手动设置:

podman pod create --name monitoring
podman network create mon
podman run -d --rm --network=mon --pod=monitoring --name postgres-server docker.io/timescale/timescaledb:latest-pg14
podman run -d --rm --network=mon --pod=monitoring --name zabbix-server docker.io/zabbix/zabbix-server-pgsql

周一网络配置:

[
    {
        "cniVersion": "0.4.0",
        "name": "mon",
        "plugins": [
            {
                "bridge": "cni-podman1",
                "hairpinMode": true,
                "ipMasq": true,
                "ipam": {
                    "ranges": [
                        [
                            {
                                "gateway": "10.89.0.1",
                                "subnet": "10.89.0.0/24"
                            }
                        ]
                    ],
                    "routes": [
                        {
                            "dst": "0.0.0.0/0"
                        }
                    ],
                    "type": "host-local"
                },
                "isGateway": true,
                "type": "bridge"
            },
            {
                "capabilities": {
                    "portMappings": true
                },
                "type": "portmap"
            },
            {
                "backend": "",
                "type": "firewall"
            },
            {
                "type": "tuning"
            },
            {
                "capabilities": {
                    "aliases": true
                },
                "domainName": "dns.podman",
                "type": "dnsname"
            }
        ]
    }
]

监控.yaml文件:

# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-3.4.7
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2022-05-24T13:40:30Z"
  labels:
    app: monitoring
  name: monitoring
spec:
  containers:
  - args:
    - postgres
    image: docker.io/timescale/timescaledb:latest-pg14
    name: postgres-server
    resources: {}
    securityContext:
      capabilities:
        drop:
        - CAP_MKNOD
        - CAP_NET_RAW
        - CAP_AUDIT_WRITE
  - args:
    - /usr/sbin/zabbix_server
    - --foreground
    - -c
    - /etc/zabbix/zabbix_server.conf
    image: docker.io/zabbix/zabbix-server-pgsql:latest
    name: zabbix-server
    resources: {}
    securityContext:
      capabilities:
        drop:
        - CAP_MKNOD
        - CAP_NET_RAW
        - CAP_AUDIT_WRITE
    volumeMounts:
    - mountPath: /var/lib/zabbix/export
      name: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8-pvc
    - mountPath: /var/lib/zabbix/snmptraps
      name: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec-pvc
  restartPolicy: Never
  volumes:
  - name: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8-pvc
    persistentVolumeClaim:
      claimName: bdc06ccb2b092148bb78c353fccc104255a81a8735eb3a14974f6ede0e6516e8
  - name: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec-pvc
    persistentVolumeClaim:
      claimName: 196d7983e1b62995bae07beb7942e18ac46dcf6d3346e43fff2604c9a7bc30ec
status: {}

故障排除

podman 文档表明podman network create支持附加创建的网络:https ://docs.podman.io/en/latest/markdown/podman-play-kube.1.html#network-mode-net

在手动podman exec -it <container> /bin/bash创建的容器上打开 shell ( ) ,我可以 ping zabbix-server 和 postgres-server:

$ podman exec -it zabbix-server /bin/bash
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.89.0.3       c61fdf070064 zabbix-server
10.89.0.1 host.containers.internal
bash-5.1$ ping postgres-server
PING postgres-server.dns.podman (10.89.0.2) 56(84) bytes of data.
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=1 ttl=64 time=0.051 ms
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=2 ttl=64 time=0.062 ms
64 bytes from postgres-server.dns.podman (10.89.0.2): icmp_seq=3 ttl=64 time=0.100 ms
^C
--- postgres-server.dns.podman ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2045ms
rtt min/avg/max/mdev = 0.051/0.071/0.100/0.021 ms

在play kube容器上,ping 要么monitoring-<name>-server失败<name>-server。ping 手册和 play kube 设置上的 DNS 解析器成功返回。

bash-5.1$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.89.0.2       monitoring be3df46ca68d-infra
10.89.0.1 host.containers.internal

bash-5.1$ ping postgres-server
ping: postgres-server: Name does not resolve
bash-5.1$ ping monitoring-postgres-server
ping: monitoring-postgres-server: Name does not resolve
bash-5.1$ cat /etc/resolv.conf
search dns.podman
nameserver 10.89.0.1

使用podman inspect <container>,手动和 kube 播放设置都连接了 'mon' 网络。但是,在play kube设置中,网络设置的输出如下:

"NetworkMode": "container:49e7b0bafd4619b9bcb50b1b841aeee3cb910bf3c555a9788dc297e71c948092"

这与手动网络设置不同:

"NetworkMode": "bridge"

看起来好像“play kube”忽略了 --network 标志,而是创建了一个内部容器网络。使用kube play查看容器网络设置,两个容器上的 ips 是相同的。在手动设置中,IP 不同:

"Networks": {              
                "mon": {            
                    "EndpointID": "",
                    "Gateway": "10.89.0.1",
                    "IPAddress": "10.89.0.3",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "3e:30:b7:e2:1d:00",
                    "NetworkID": "mon",

Networks": {              
                "mon": {            
                    "EndpointID": "",
                    "Gateway": "10.89.0.1",
                    "IPAddress": "10.89.0.2",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "fa:1a:6b:f3:02:3a",
                    "NetworkID": "mon",

我已经在 Enforcing 模式下尝试了使用和不使用 SELinux 的 podman kube play。我也尝试以 root 身份运行此设置,但无济于事。

我已经使用以下版本测试了此设置:

  • 播客:3.4.7、4.0.2
  • RHEL:8.5、8.6

任何帮助将非常感激!

rhel container
  • 1 1 个回答
  • 232 Views

1 个回答

  • Voted
  1. Best Answer
    Chuck
    2022-05-26T18:14:00+08:002022-05-26T18:14:00+08:00

    我找到了解决方案。使用创建的容器podman play kube共享一个网络命名空间。因此,他们可以使用localhost.

    • 1

相关问题

  • 为什么 Linux 会杀死我的进程?

  • linux redhat 7 ( 或 centos 7 ) + firewalld 屏蔽防火墙

  • systemctl 命令在 RHEL 6 中不起作用

  • 如何在 RHEL 7 上离线安装 docker?

  • 在 Gnome3 中禁用窗口的自动最大化

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve