在 VirtualBox 的多集群 kubernetes 环境中访问部署的应用程序时遇到问题
Having problem to access deployed application in multiclustering kubernetes environment in 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
终于找到解决办法了。感谢 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-node-121 Hosts (/etc/hosts)
master-16-120 192.168.0.120
16-node-121 192.168.0.121
现在我的 kubernetes 已经准备好了。
我已经创建了多集群 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
终于找到解决办法了。感谢 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-node-121 Hosts (/etc/hosts)
master-16-120 192.168.0.120
16-node-121 192.168.0.121
现在我的 kubernetes 已经准备好了。