在vagrant 创建的VirtualBox 里部署了k8s ,

[root@master yaml]# kubectl get pods
NAME                          READY   STATUS             RESTARTS   AGE
app-7bcbdd4dfd-l2xkv          0/1     CrashLoopBackOff   582        2d5h
db-756759796-gfl8d            1/1     Running            0          25m
mosquitto-c5ddcff77-qvzhr     1/1     Running            1          2d5h
mqtt-7b9dcdc467-cxwrm         1/1     Running            1          2d5h
web-server-77d9d9f8fc-4lnn2   1/1     Running            1          2d5h

但是:

[root@master yaml]# kubectl exec -it db-756759796-gfl8d bash
error: unable to upgrade connection: pod does not exist
[root@master yaml]# kubectl exec -it db-756759796-gfl8d bash
error: unable to upgrade connection: pod does not exist

原因是 vagrant 创建的box,eth0 ip默认是10开头的。eth1才是可以互联的IP。
因此需要指定一下。

在master 和 worker (node)上都做修改
注意。

CENTOS 中,打开:/etc/sysconfig/kubelet

ubuntu中,打开:/etc/systemd/system/kubelet.service.d/10-kubeadm.conf

#/etc/default/kubernetes ,添加如下内容:--node-ip

KUBELET_EXTRA_ARGS=--node-ip=ABCXYZ 
ABCXYZ为eth1的IP。

重启kubelet

systemctl restart kubelet

然后查看:

[root@master yaml]# kubectl get nodes -o wide
NAME                  STATUS   ROLES    AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
master.localdomain    Ready    master   3d    v1.16.0   192.168.56.9    <none>        CentOS Linux 7 (Core)   3.10.0-1160.53.1.el7.x86_64   docker://18.9.9
worker1.localdomain   Ready    <none>   3d    v1.16.0   192.168.56.10   <none>        CentOS Linux 7 (Core)   3.10.0-1127.el7.x86_64        docker://18.9.9
worker2               Ready    <none>   3d    v1.16.0   192.168.56.11   <none>        CentOS Linux 7 (Core)   3.10.0-1127.el7.x86_64        docker://18.9.9

INTERNAL-IP显示正常了。

参考:
https://stackoverflow.com/questions/51154911/kubectl-exec-results-in-error-unable-to-upgrade-connection-pod-does-not-exi

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐