Load balancing not happening in Kubernetes

10/29/2020

I've recently started learning Kubernetes and have run into a problem. I'm trying to deploy 2 pods which run the same docker image, to do that I've mentioned replicas: 2 in the deployment.yaml. I've also mentioned a service as a LoadBalancer with external traffic policy as cluster. I confirmed that there are 2 end points by doing kubectl describe service. The session persistence also was set to none. When I send requests repeatedly to the service port, all of them are routed to only one of the pods, the other one just sits there. How can I make this more efficient? Or any insignts as to what might be going wrong? Here's the deployment.yaml file EDIT: The solutions mentioned on Only 1 pod handles all requests in Kubernetes cluster didn't work for me.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: project-nameprodmstb
  labels:
    app: project-nameprodmstb
spec:
  replicas: 2
  selector:
    matchLabels:
      app: project-nameprodmstb
  template:
    metadata:
      labels:
        app: project-nameprodmstb
    spec:
      containers:
        - name: project-nameprodmstb
          image: <some_image>
          imagePullPolicy: Always
          resources:
            requests:
              cpu: "1024m"
              memory: "4096Mi"
      imagePullSecrets:
        - name: "gcr-json-key"
      
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: project-nameprodmstb
  name: project-nameprodmstb 
  namespace: development
spec:
  ports:
  - name: project-nameprodmstb
    port: 8006
    protocol: TCP
    targetPort: 8006
  selector:
    app: project-nameprodmstb
  type: LoadBalancer
-- Aseem Kannal
azure-aks
kubernetes
load-balancing

0 Answers