在VirtualBox的多集群kubernetes环境中访问已部署的应用程序时遇到问题

时间:2019-04-20 10:25:00

标签: docker kubernetes virtualbox

我已经创建了多集群kubernetes环境,我的节点详细信息是:

kubectl get nodes -o wide

NAME            STATUS   ROLES    AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
16-node-121     Ready    <none>   32m   v1.14.1   192.168.0.121   <none>        Ubuntu 16.04.6 LTS   4.4.0-142-generic   docker://18.9.2
master-16-120   Ready    master   47m   v1.14.1   192.168.0.120   <none>        Ubuntu 16.04.6 LTS   4.4.0-142-generic   docker://18.9.2

然后我创建了一个服务,并使用以下命令公开了该服务:

$kubectl expose deployment hello-world --port=80 --target-port=8080

已创建并公开。我的服务详细信息是:

NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
hello-world   ClusterIP   10.105.7.156   <none>        80/TCP    33m

我通过以下命令公开了部署:

kubectl expose deployment hello-world --port=80 --target-port=8080
service/hello-world exposed

不幸的是,当我尝试使用curl命令访问服务时,出现超时错误:

我的服务详细信息如下:

master-16-120@master-16-120:~$ kubectl describe service hello-world
Name:              hello-world
Namespace:         default
Labels:            run=hello-world
Annotations:       <none>
Selector:          run=hello-world
Type:              ClusterIP
IP:                10.105.7.156
Port:              <unset>  80/TCP
TargetPort:        8080/TCP
Endpoints:         192.168.1.2:8080
Session Affinity:  None
Events:            <none>



curl http://10.105.7.156:80
curl: (7) Failed to connect to 10.105.7.156 port 80: Connection timed out

在这里,我将calico用于多集群网络:

wget https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
wget https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

我的Pod网络规范是:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

1 个答案:

答案 0 :(得分:0)

最后我得到了解决方案。感谢Daniel的评论,这有助于我找到解决方案。

我将我的kubernetis pod网络CIDR和calico更改如下:

--pod-network-cidr=10.10.0.0/16

还要配置master-master 16-120个主机(/ etc / hosts):

master-16-120 192.168.0.120
16-node-121 192.168.0.121

在16节点121主机(/ etc / hosts)的节点中

master-16-120 192.168.0.120
16-node-121 192.168.0.121

现在我的kubernetes已准备就绪。