How to distribute requests to pods on a Kubernetes service

7/21/2018

I have a service and 4 pods which wordpress installed on each. This is my service configuration:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - port: 31001
    nodePort: 31001
    targetPort: apache
    protocol: TCP
  selector:
    app: wordpress
  type: NodePort

Now all traffic are distributed randomly by the service. I want to change it that work non-random (I think It's name was round robin). I have read the official document but I don't understand it.

Is there any way to manage traffic respectively? Could anybody please show me an example?

-- Meysam Mahmoodi
kubernetes

1 Answer

7/23/2018

As @Meysam mentioned, Kubernetes service distributes the request to pods using "round robin" technology by default.

I would advise you (and all who will read this topic in the future) to read more information about Kubernetes Services and How does kubernetes handle load balancing. It will shed a light on tons of questions.

Kubernetes uses a feature called kube-proxy to handle the virtual IPs for services. Kubernetes allocates tasks to pods within a service by the round-robin method

With round-robin allocation, the system maintains a list of destinations. When a request comes in, it assigns the request to the next destination on the list, then permutes the list (either by simple rotation, or a more complex method), so the next request goes to the following destination on the list.

-- VKR
Source: StackOverflow