Google Compute kubernetes only can be access when nodePort on NodePort service is 80

10/18/2018

Somehow, I am trying to start a kubernetes project on Google Compute (not GKE). After all installation (read docker-ce, kubelet, kubeadm) I create a Service and a Deployment inside as follows :

apiVersion : v1
kind : Service
metadata:
  name: client-node-port
spec:
  type: NodePort
  ports:
  - port: 90
    targetPort: 80
    nodePort: 31515
  selector:
    component: web

It was working until I change the targetPort inside service to any port beside 80 (along with the Deployment containerPort).

I already tried enabling the port on the instance firewall-cmd --permanent --add-port=(any port beside 80)/tcp

Beside that I also already enable the firewall rule in google Google Firewall Setting

Is there anything that I missed ? Why I can only access the NodePort when nodePort setting in the service is 80 ?

Thanks

PS : If it is relevant, I am using flannel network

-- thegexploit
docker
docker-compose
flannel
google-cloud-platform
kubernetes

1 Answer

10/18/2018

May I know why you are trying to change targetPort ?

TargetPortis the port on the POD where the service is running.

Nodeportis the port on which the service can be accessed from external users by nodeip:nodeport.

Port: the same as Nodeport but can be used by cluster users using clusterip:port.

Again, in your case port 80 represents the service is actually running on port 80.

You should change targetPortin case you will set the service in the pod that is running on a different port.

Review this question for more details.

-- VKR
Source: StackOverflow