Kubernetes LoadBalancer doesn't work properly

Viewed 32

I made simple Java web app (secure.war) with Tomcat (tomcat:9.0-alpine) and I expected that requests will be balanced among pods in Kubernetes. I even set maxKeepAliveRequests="1" in Tomcat connector (server.xml) to turn off Keep-Alive features. I use Minikube to run it locally. My configs:

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deployment
  labels:
    app: tomcat
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
        - name: tomcat
          image: optionix/mywebapp:5.3
          ports:
            - containerPort: 8080

service.yaml

kind: Service
apiVersion: v1
metadata:
  name: v-service
spec:
  type: LoadBalancer
  selector:
    app: tomcat
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080

Then I run:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl port-forward services/v-service 8080:8080

Now you can make requests on http://localhost:8080/secure/getId and you will see UUID which was generated at application startup.

Actual behaviour: you always see the same UUID (it means that only one pod receive requests)

Expected behaviour: you see two different UUID one by one randomly (which means that requests balancing among two pods)

0 Answers
Related