There is no listening port on slave-node host when exposing service via kubectl

6/17/2019

I'm setting up a kubernetes cluster, having one master node(a physical miniPC, running ubuntu server 18.04) and one slave-node(a laptop, running ubuntu 16.04).

Docker is the container I'm using in conjunction with kubernetes.

I run a demo application via

kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0  --port 8080

and expose it via

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

The application starts on slave-node

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

And I can access it from inside the container

alecu@slave-node:~$ sudo nsenter -t 21075 -n curl http://localhost:8080
Hello, world!
Version: 1.0.0
Hostname: hello-world-6899bf7846-t5pb7

But when I try to access it from outside the container I get connection refused:

alecu@slave-node:~$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

netstat is not showing 8080 port

alecu@slave-node:~$ netstat -tnlp | grep 8080

curl is not working from master-node either

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:~$

I 'ctrl+c'ed the curl command as it was endlessly waiting.

I do not get it why on slave-node port 8080 is not opened.

[EDIT] I patched the service to use NodePort

 kubectl patch svc hello-world --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'

but the curl is not working either on 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
-- Alecu Constantin-Alexandru
docker
kubernetes

2 Answers

6/17/2019

I found out the problem.

I used two faulty networking pods that were indicated in a pluralsight course.

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

After applying those two pods, no connection could be made to any website, neither to the cluster.

I replaced them with flannel as networking pod and everything is working fine.

https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
-- Alecu Constantin-Alexandru
Source: StackOverflow

6/17/2019

update the service type to NodePort. then you should be able to access the app from outside using http://NODEIP:NODEPORT Or use the clusterIP to access the app from the cluster.

get the clusterIP from below command

kubectl get svc

see below for instructions

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
-- P Ekambaram
Source: StackOverflow