我正在设置一个kubernetes集群,它有一个主节点(一个物理miniPC,运行ubuntu服务器18.04)和一个从节点(一个笔记本电脑,运行ubuntu16.04)。
Docker是我和kubernetes一起使用的容器。
我通过运行一个演示应用程序
kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0 --port 8080
并通过以下方式公开它
kubectl expose deployment hello-world --port=8080 --target-port=8080
应用程序在从节点上启动
alecu@slave-node:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91967f160a7c bc5c421ecd6c "./hello-app" About an hour ago Up About an hour k8s_hello-world_hello-world-5bcc568dd9-xktwg_default_875609f4-90d0-11e9-9940-7cd30a0da72f_0
我可以从容器内部访问它
alecu@slave-node:~$ sudo nsenter -t 21075 -n curl http://localhost:8080
Hello, world!
Version: 1.0.0
Hostname: hello-world-6899bf7846-t5pb7
但是当我试图从容器外部访问它时,我得到的连接被拒绝:
alecu@slave-node:~$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused
netstat未显示8080端口
alecu@slave-node:~$ netstat -tnlp | grep 8080
curl也不能在主节点上工作
alecu@master-node:~$ kubectl describe service hello-world
Name: hello-world
Namespace: default
Labels: <none>
Annotations: <none>
Selector: run=hello-world
Type: ClusterIP
IP: 10.100.48.99
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
Endpoints: 192.168.1.18:8080
Session Affinity: None
Events: <none>
alecu@master-node:~$ curl -v http://192.168.1.18:8080
* Rebuilt URL to: http://192.168.1.18:8080/
* Trying 192.168.1.18...
* TCP_NODELAY set
^C
alecu@master-node:~$ curl -v http://10.100.48.99:8080
* Rebuilt URL to: http://10.100.48.99:8080/
* Trying 10.100.48.99...
* TCP_NODELAY set
^C
alecu@master-node:~$
我使用了ctrl+c‘命令,因为它正在无休止地等待。
我不明白为什么从节点上的端口8080没有打开。
编辑我已将服务修补为使用NodePort
kubectl patch svc hello-world --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
但是curl在http://nodeIP:nodePort上也不起作用
alecu@master-node:~$ kubectl describe svc hello-world
Name: hello-world
Namespace: default
Labels: run=hello-world
Annotations: <none>
Selector: run=hello-world
Type: NodePort
IP: 10.100.171.36
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 30988/TCP
Endpoints: 192.168.1.21:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
alecu@master-node:~$ curl -v http://10.100.171.36:30988
* Rebuilt URL to: http://10.100.171.36:30988/
* Trying 10.100.171.36...
* TCP_NODELAY set
^C
发布于 2019-06-17 08:47:41
将服务类型更新为NodePort。然后,您应该能够使用http://NODEIP:NODEPORT从外部访问应用程序,或者使用clusterIP从集群访问应用程序。
从下面的命令获取clusterIP
kubectl get svc
请参阅下面的说明
master $ kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0 --port 8080
deployment.apps/hello-world created
master $
master $ kubectl expose deployment hello-world --port=8080 --target-port=8080
service/hello-world exposed
master $
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world ClusterIP 10.104.172.60 <none> 8080/TCP 4s
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 1h
master $
master $ curl 10.104.172.60:8080
Hello, world!
Version: 1.0.0
Hostname: hello-world-6654767c49-r2mnz
发布于 2019-06-17 18:07:27
我发现了问题所在。
我使用了pluralsight课程中指出的两个有故障的网络pod。
https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
应用这两个pod后,无法连接到任何网站,也无法连接到集群。
我将它们替换为flannel作为网络pod,一切工作正常。
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
https://stackoverflow.com/questions/56627548
复制相似问题