1

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
  • 83
  • 1
  • 1
  • 7
  • Consider adding the actual kubernetes yaml definition file(s) for the deployment, service, etc. – Mark Bramnik Oct 29 '20 at 05:20
  • Check the Ready status on both pods. Traffic is only sent to Ready pods. – coderanger Oct 29 '20 at 05:34
  • Yes, I checked that too. 'Ready' is true for both the pods. – Aseem Kannal Oct 29 '20 at 05:52
  • Does this answer your question? [Only 1 pod handles all requests in Kubernetes cluster](https://stackoverflow.com/questions/58580778/only-1-pod-handles-all-requests-in-kubernetes-cluster) – Kamol Hasan Oct 29 '20 at 06:14
  • Yeah, I tried that too. Disabled keep-alive while making the request, the horizintal scaler spawns more replicas, I can see the cpu load increasing but still, requests are sent to a single pod. – Aseem Kannal Oct 29 '20 at 06:36
  • 1
    Can you try to create another Service with type: ClusterIP and send request inside cluster? see if it works – RammusXu Oct 29 '20 at 08:42
  • Also, how do you host kubernetes? GKE, EKS, k3s, etc.. – RammusXu Oct 29 '20 at 08:43
  • @RammusXu Yeah, I tried that too, it still doesn't work. All requests being forwarded to the same pod. And I'm using AKS. – Aseem Kannal Oct 29 '20 at 09:54

0 Answers0