I have strange issue with
NodePort service on multi nodes. Lets me explain full situation.
I have bare-metal kubernetes cluster with 3 nodes: 1 master and 2 worker nodes.
Workers nodes have the next external IPs (these IPs are only examples):
- node1: 100.100.100.101
- node2: 100.100.100.102
I have created Deployment (with one replica) for simple nginx container and NodePort service for this deployment using this configuration:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 selector: matchLabels: app: nginx-example template: metadata: labels: app: nginx-example spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 --- kind: Service apiVersion: v1 metadata: name: nginx-example-service spec: selector: app: nginx-example ports: - protocol: TCP targetPort: 80 port: 80 name: http type: NodePort
It means that I want to create access to this container via nodeIP:servicePort, for example - 100.100.100.102:80 should forward my request into this Nginx container.
Pod is created on node2:
NAME READY STATUS RESTARTS AGE IP NODE nginx-deployment-7fdcd5bc84-c5gnz 1/1 Running 0 4m 192.168.136.164 kubernetes-main-node-2
And service exists:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-example-service NodePort 10.106.51.84 <none> 80:32570/TCP 6s
But there is a strange thing appear. For origin documentation I see the next:
If you set the type field to NodePort, the Kubernetes master will allocate a port from a range specified by --service-node-port-range flag (default: 30000-32767), and **each Node** will proxy that port (the same port number on every Node) into your Service.
But it doesn’t work. Nodes do not forward nodes traffic from 80 port into this service.
100.100.100.101:80 - KO
100.100.100.101:32570 - KO
100.100.100.102:80 - KO
100.100.100.102:32570 - OK
Only node on which pod is running, forward this automatically allocated port (32570 from example).
Question 1: Why do not all nodes forward traffic into service?
Question 2: Why traffic from the port I specified (in this example it’s 80 port) is not forwarded to the service?
Question 3: What I’m doing wrong?