azurekubernetesflaskazure-aksreplicaset

Why does my Flask application only work properly on AKS with one replica?


When I deploy a simple flask application on AKS with one replica, the application is running as expected. But when I deploy the application with two replicas, it was not working as expected. User not able to redirect home page post sign in was successful, sometimes it works.

How do we manage the flask application with two replicas?

Here are my kubernetes manifests for your reference.

Thanks

Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontpage
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: frontpage
  template:
    metadata:
      labels:
        app: frontpage
    spec:
      containers:
      - name: frontpage
        image: ***.azurecr.io/frontpage:latest
        limits:
        ports:
        - containerPort: 5000

Service.yaml

apiVersion: v1
kind: Service
metadata:
  name: frontpage
  namespace: default
spec:
  selector:
    app: frontpage
  ports:
  - name: http
    port: 80
    targetPort: 5000
  type: ClusterIP

Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: frontpage
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - www.***.com
    secretName: ingress-tls-csi
  rules:
  - host: www.***.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: frontpage
            port:
              number: 80

Solution

  • Try to delete the annotation nginx.ingress.kubernetes.io/rewrite-target or to add the captured group.


    UPDATE

    Your application uses a file system session affinity and therefore contains a state (see SESSION_TYPE). This state is not shared between your replicas.

    Can you change the session backend? You can also probably share the backend with a volume between replicas for testing.