I have set a up a kubernetes cluster in Oracle Virtualbox with one master VM (192.168.0.150) and two worker VMs (.151 and .152) connected via Virtualbox's "Bridged Adapter". I am using flannel network and the CIDR of the pod network is 10.244.0.0/16. I have created a deployment consisting 4 replicas of nginx server, with a service using the nodePort 30300.
I am testing the system with "curl 'IP of worker node':30300" and I have experienced that about the 50% of requests served properly by the nginx server, but the other half returns with an error: "curl: (7) Failed to connect to 192.168.0.151:30300: No route to host". I suspect that the requests get served when the scheduler returns a pod which is running on the current worker node (the node with the IP used in the curl request), but if the scheduler gives a pod which is situated on the other node, than the packet is not forwarded to that node.
Is is possible to use nodePort service with multiple worker nodes and without external load balancer?
Here you can see my yaml files used for creating the deployment and the service:
--- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 4 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.15.4 ports: - containerPort: 80
--- apiVersion: v1 kind: Service metadata: name: nginx-service labels: app: nginx spec: ports: - port: 8080 targetPort: 80 name: web nodePort: 30300 type: NodePort selector: app: nginx