AKS pod websocket connection is breaking

VENKAT THARUN D A 0 Reputation points
2024-06-12T07:22:36.11+00:00

I am using AKS to run my pods and Azure Application Gateway as a web traffic load balancer. I have an issue with one of the pods using WebSocket, the WebSocket connection is breaking. The Application Gateway documentation states that Application Gateway provides native support for WebSocket, but the connection is not being maintained. I also tested this in App Service, where the connection does not break. What steps need to be implemented to maintain the connection in the AKS pod?

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,996 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anveshreddy Nimmala 3,535 Reputation points Microsoft Vendor
    2024-06-13T07:12:36.24+00:00

    Hello Venkat Tharun D A,

    Kubernetes deployment YAML shows the minimum configuration used to deploy a WebSocket server. After all the prerequisites are fulfilled, and you have an Application Gateway controlled by a Kubernetes Ingress in your AKS, the deployment shown would expose a WebSockets server on port 80 of your Application Gateway's public IP and the ws.contoso.com domain.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: websocket-server
    spec:
      selector:
        matchLabels:
          app: ws-app
      replicas: 2
      template:
        metadata:
          labels:
            app: ws-app
        spec:
          containers:
            - name: websocket-app
              imagePullPolicy: Always
              image: your-container-repo.azurecr.io/websockets-app
              ports:
                - containerPort: 8888
          imagePullSecrets:
            - name: azure-container-registry-credentials
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: websocket-app-service
    spec:
      selector:
        app: ws-app
      ports:
      - protocol: TCP
        port: 80
        targetPort: 8888
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: websocket-repeater
      annotations:
        kubernetes.io/ingress.class: azure/application-gateway
    spec:
      rules:
        - host: ws.contoso.com
          http:
            paths:
              - backend:
                  serviceName: websocket-app-service
                  servicePort: 80
    

    please find the below documentation link for the same .

    https://learn.microsoft.com/en-us/azure/application-gateway/ingress-controller-expose-websocket-server

    Hope this helps you.

    0 comments No comments