不能通过NodePort访问kubernetes

时间:2017-06-19 05:31:50

标签: kubernetes

在部署Guestbook example之后,我陷入了NodeIP无法访问的问题:NodePort。有没有人遇到同样的问题而且已经修好了?欢迎任何帮助。

描述

无法通过 curl [NodeIP]:[NodePort] 进行访问,通过busybox Pod中的端点进行访问。

  • cmd netstat -ntpl|grep 30061的结果 tcp6 0 0 :::30061 :::* LISTEN 14790/kube-proxy
  • cmd curl 127.0.0.1:30061 -v的结果 About to connect() to 127.0.0.1 port 30061 (#0) Trying 127.0.0.1... Connection refused Failed connect to 127.0.0.1:30061; Connection refused Closing connection 0 curl: (7) Failed connect to 127.0.0.1:30061; Connection refused

cluser info

  • 机器:3 * CentOS VM
  • kubernetes版本 Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
  • cmd kubectl get endpoints的结果 NAME ENDPOINTS AGE frontend 172.17.81.4:8020 2d kubernetes 10.202.130.190:6443 6d redis-master 172.17.81.2:6379 2d redis-slave 172.17.50.5:6379,172.17.81.3:6379 2d
  • cmd kubectl get service的结果 NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE frontend 10.254.104.214 <nodes> 80:30061/TCP 2d kubernetes 10.254.0.1 <none> 443/TCP 6d nginxsvc 10.254.69.133 <nodes> 80:32196/TCP,443:30793/TCP 4d redis-master 10.254.85.103 <none> 6379/TCP 2d redis-slave 10.254.137.163 <none> 6379/TCP 2d
  • 服务前端的端口配置

ports: - port: 80 nodePort: 30061 targetPort: 8020 selector: app: guestbook ti

1 个答案:

答案 0 :(得分:-1)

  

如果要从群集外部访问留言簿 ,请将type: NodePort添加到前端服务规范字段。

     

然后,您可以使用群集外部的<NodeIP>:NodePort 访问留言簿

     

在支持外部负载均衡器的云提供商上,将type: LoadBalancer添加到前端服务规范字段将为您的服务配置负载均衡器。

似乎您从本地主机访问它,然后您应该运行

kubectl cluster-info然后运行

curl <kubernets_master_ip>:30061