kubernetes not forwarding packets between nodes

1/15/2019

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:

deployment.yaml:

---
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

service.yaml

---
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
-- stdt
kubernetes

1 Answer

1/15/2019

Exactly, the purpose of using a NodePort is not to use an external load balancer and use your own in your subnet. There is nothing wrong with your configuration. To make it sure that your problem is cluster networking, try the following: you can scale your replica to "1", then check the same way for both IP addresses. You need to get an answer from both node IP addresses. If not, check if your ports and firewall are configured correctly. Also, you can check the guide that you used to deploy Kubernetes cluster or kubeadm.

-- coolinuxoid
Source: StackOverflow