kubernetes not access by NodePort

6/19/2017

After deploy Guestbook example, I'm stuck in the problem that I can't access by NodeIP:NodePort. Does anybody meet the same problem and have fixed? Any help is welcome.

Description

not access via curl [NodeIP]:[NodePort], access via endpoints in busybox Pod.

  • result of cmd netstat -ntpl|grep 30061 tcp6 0 0 :::30061 :::* LISTEN 14790/kube-proxy
  • result of 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

  • Machine: 3 * CentOS VM
  • kubernetes Version 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"}
  • result of 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
  • result of 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
  • the port config of service frontend

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

-- onebraveman
kubernetes

1 Answer

6/19/2017

If you want to access the guestbook from outside of the cluster, add type: NodePort to the frontend Service spec field.

Then you can access the guestbook with <NodeIP>:NodePort from outside of the cluster.

On cloud providers which support external load balancers, adding type: LoadBalancer to the front end Service spec field will provision a load balancer for your Service.


Seems that you are accessing it from your localhost, then you should run

kubectl cluster-info then run

curl <kubernets_master_ip>:30061

-- deepak
Source: StackOverflow