3

我初始化了一个 5 节点的 k8s 集群,如下所示:

[root@lpdkubpoc01a ~]# kubeadm init --pod-network-cidr=10.96.0.0/16 --service-cidr=10.97.0.0/16 --image-repository quaytest.phx.aexp.com/control-plane
W0727 15:19:51.123991    1866 version.go:101] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://dl.k8s.io/release/stable-1.txt: dial tcp: lookup dl.k8s.io on 10.2.88.196:53: no such host
W0727 15:19:51.124080    1866 version.go:102] falling back to the local client version: v1.17.5
W0727 15:19:51.124236    1866 validation.go:28] Cannot validate kube-proxy config - no validator is available
W0727 15:19:51.124244    1866 validation.go:28] Cannot validate kubelet config - no validator is available
[init] Using Kubernetes version: v1.17.5
[preflight] Running pre-flight checks
...
...
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:
```bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

您现在应该将 pod 网络部署到集群。使用以下列出的选项之一运行“kubectl apply -f [podnetwork].yaml”: https ://kubernetes.io/docs/concepts/cluster-administration/addons/

然后,您可以通过以 root 身份在每个节点上运行以下命令来加入任意数量的工作节点:

kubeadm join 10.22.76.244:6443 --token fa5ia8.oqs7jv9ii6wzex0w \
    --discovery-token-ca-cert-hash sha256:6680c99e6c49e0dce4522bc9768bfc2e7e2b38f5a10668d3a544554ab0d09ff1

根据上述说明,我运行以下命令:

[root@lpdkubpoc01a ~]# mkdir -p $HOME/.kube
[root@lpdkubpoc01a ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: overwrite ‘/root/.kube/config’? y
[root@lpdkubpoc01a ~]# chown $(id -u):$(id -g) $HOME/.kube/config

但是当我检查控制平面组件 pod 时,我看到它们都初始化为

  1. 相同的IP地址

  2. 不正确的 CIDR => 似乎在主机网络中,这是一个很大的 NO-NO

    [root@lpdkubpoc01a ~]# kubectl get pods -n kube-system -owide
    NAME                                                READY   STATUS    
    RESTARTS   AGE   IP             NODE                        NOMINATED NODE   READINESS GATES
    coredns-598947db54-dzrjk                            0/1     Pending   0          37s   <none>         <none>                      <none>           <none>
    coredns-598947db54-t2wch                            0/1     Pending   0          37s   <none>         <none>                      <none>           <none>
    etcd-lpdkubpoc01a.phx.aexp.com                      1/1     Running   0          50s   10.22.76.244   lpdkubpoc01a.phx.aexp.com   <none>           <none>
    kube-apiserver-lpdkubpoc01a.phx.aexp.com            1/1     Running   0          50s   10.22.76.244   lpdkubpoc01a.phx.aexp.com   <none>           <none>
    kube-controller-manager-lpdkubpoc01a.phx.aexp.com   1/1     Running   0          50s   10.22.76.244   lpdkubpoc01a.phx.aexp.com   <none>           <none>
    kube-proxy-8dbx2                                    1/1     Running   0          38s   10.22.76.244   lpdkubpoc01a.phx.aexp.com   <none>           <none>
    kube-scheduler-lpdkubpoc01a.phx.aexp.com            1/1     Running   0          50s   10.22.76.244   lpdkubpoc01a.phx.aexp.com   <none>           <none>
    

出了什么问题,我该如何补救?kube-system ns 中的 pod 不应具有相同的 IP,并且绝对不能与主机位于同一网络中:

[root@lpdkubpoc01a ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:40:17:25:e4  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

**eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.22.76.244  netmask 255.255.254.0  broadcast 10.22.77.255
        ether 00:50:56:b8:e1:84  txqueuelen 1000  (Ethernet)
        RX packets 73810789  bytes 8755922965 (8.1 GiB)
        RX errors 0  dropped 31388  overruns 0  frame 0
        TX packets 44487774  bytes 12389932340 (11.5 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0**

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9000
        inet 10.0.195.100  netmask 255.255.254.0  broadcast 10.0.195.255
        ether 00:50:56:b8:6c:23  txqueuelen 1000  (Ethernet)
        RX packets 3573616  bytes 708218742 (675.4 MiB)
        RX errors 0  dropped 50118  overruns 0  frame 0
        TX packets 830522  bytes 174979700 (166.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 263222455  bytes 44942504690 (41.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 263222455  bytes 44942504690 (41.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

谢谢!

4

3 回答 3

1

看起来您的 pod 网络甚至都没有配置好。您可以安装CalicoWeave 之类的东西。之后你的 coredns pod 应该会出现,你的其他 pod 也应该获得不同的 IP 地址。

过去,这些说明位于kubeadm 主页面上,但据我了解,它们实际上已被弃用,有利于在 CNI 上进行更多标准化,并让每个 CNI 提供者都提供自己的安装说明。

✌️

于 2020-07-27T23:08:06.137 回答
0

控制平面组件是静态 Pod,您可以在 /etc/kubernetes/manifest/ 目录中看到它们的 yaml 文件,并且主节点的 kubelete 负责检查它们是否正在运行。因此,静态 Pod 拥有其本地主机的 IP 是正常的。

顺便说一句,您仍然需要像 Calico 或 Weave 网络这样的 kubernetes 网络插件。检查此链接。
https://kubernetes.io/docs/concepts/cluster-administration/addons/
例如,在您的情况下,您只需要运行此命令即可使用所需的 pod-network-cidr 部署 weave 网络插件:

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=10.96.0.0/16"

小心在部署网络插件时指定您的 pod-network-cidr。

于 2020-09-29T19:00:30.717 回答
0

控制平面 pod 具有节点 IP 是正常的。其他一切都将从cni获得ip。

于 2020-12-24T07:02:18.277 回答