1

I've got a service running in an on premise k8s environment. It is basically an nginx image, and a call takes like 10 seconds. replicas is two and of course two pods are running. But almost if not every call goes to one pod, queueing up calls. If there's many calls they just wait until all of them are ready, not a single one goes to the other pod.

apiVersion: v1
kind: Service
metadata:
 name: revproxy-svc
spec:
 selector:
   role: app
 ports:
   - protocol: TCP
     port: 80
     targetPort: 80
     nodePort: 32001
 type: LoadBalancer
 externalName: my.domain.nl 

---

apiVersion: apps/v1
kind: Deployment
metadata:
 name: proxy-deployment 
 labels:
   role: app
spec:
 replicas: 2
 selector:
   matchLabels:
     role: app
 template:
   metadata:
     labels:
       role: app
   spec: 
     containers:
     - name: web
       image: "10.203.32.90:5000/myproxy"
       resources:
        requests:
          cpu: 500m
       env:
        - name: NODE_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
       imagePullPolicy: Always

What do we need to config to set up proper loadbalancing?

2
  • Are you using a cloud based Kubernetes ? If so, you should troubleshoot on the cloud provider level.
    – Hedi Nasr
    Sep 1 at 13:00
  • forgot to mention, its on premise Sep 1 at 13:14
2

If you're trying to use a NodePort, then your Service type should be NodePort.

     nodePort: 32001
     type: NodePort      #(not LoadBalancer)

It is my understanding that the LoadBalancer type is essentially built for cloud environments where the cloud provider provides a load balancer. You are NOT creating a load balancer by creating a LoadBalancer Service type. The load balancer is a separate thing. The Cluster type is supposed to load balance internally, but I haven't been able to produce that behavior reliably. Options for the integrated load balancer to work with LoadBalancer type, on premise, seem to be incredibly limited. You can use a standard load balancer, like HAProxy, outside the cluster environment, with NodePort type on the backend.

1
  • yeah it seems so that it's limited. Thinking of creating a simple python script which round robins through the ip's of the cluster myself Sep 3 at 5:44
1

Suddenly found the answer with ipvs.

All that had to be done was put kube-proxy in ipvs mode with rr (roundrobin) scheduler.

kubectl -n kube-system edit cm kube-proxy

scheduler: "rr"
mode: ipvs

Then restart kube-proxy and we have proper loadbalancing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.