首页 > 解决方案 > 具有两个网络接口的 Kubernetes 互联网访问

问题描述

我是 Kubernetes 的新手,我有一个关于 Kubernetes 网络的问题。在我的设置中,每个节点都有两个接口。第一个接口 (eth0) 在私有范围内(例如 172.20.12.10),第二个有公共地址。

auto eth0 
iface eth0 inet static
    address 172.20.12.10
    netmask 255.255.0.0
    network 172.20.0.0
    broadcast 172.16.255.255
    dns-nameservers 8.8.8.8
auto eth1
iface eth1 inet static
address x.x.x.x
gateway y.y.y.y 

显然 kubernetes 网络配置取决于节点默认网关,因此上述节点网络配置无法正常工作。

我的问题是:如何在我的容器中访问互联网?

标签: kubernetescontainers

解决方案


--apiserver-advertise-address参数 for可kubeadm init用于使 k8s 使用不同于节点默认网络接口的接口:

--apiserver-advertise-address string
    The IP address the API Server will advertise it's listening on.
    Specify '0.0.0.0' to use the address of the default network interface.

另外,添加一个标志来/etc/systemd/system/kubelet.service.d/10-kubeadm.conf指定工作节点的私有 IP:

--node-ip=<private-node-ip>

最后,当您kubeadm join在工作节点上运行时,请确保您提供 API 服务器的私有 IP。

更多信息在:


推荐阅读