Nginx request for two or more nodes in Kubernetes

2/9/2019

I'm trying to understand some concepts behind kubernetes, so i have the following:

  1. A kubernetes cluster with 2 nodes
  2. A deployment of nginx with 2 replicas, so i have 2 POD's.
  3. A service exposing nginx on port 32134, so i can access each node with:

    http://node01:32134 or http://node02:32134

So, let's go to my doubts:

  1. Doing a kubectl describe pod nginx-001 i got this pod running under node01. Doing the same command to pod nginx-002 i got this pod running under node01 also. So, if my pods are running under only one node how i can get HTTP 200 in both URL (node01 and node02) ? Node02 should not respond because don't have any nginx running, right ?

  2. Looking at kubctl logs -f nginx-001 i got all access requests log. The strange thing is: Don't matter if i hit http://node01 or http://node02 i always get logs in nginx-001 POD, the other pod (nginx-002) never get requests in log. Seems like ks8 is redirecting all requests to nginx-001 always and forget the other pod.

Important note I'm using Digital Ocean Kubernetes services

-- Ronaldo Lanhellas
kubernetes

1 Answer

2/9/2019

1) Thats where kube-proxy steps in. Kube-proxy is responsible to route your requests to the pods, irrespective of where the pod is deployed. You could have a 50 node cluster. You could have a 10 replica nginx deployed will all replicas deployed on only 1 node and it will be kube-proxy's job to route the requests to the service.

2) That basically depends on how much load you're encountering. You probably are the only one hitting the nginx service. So it persists on sending requests to one pod. Kubernetes service enables load balancing across a set of server pods, allowing client pods to operate independently and durably.

--
Source: StackOverflow