Stickiness not working on request header for Ambassador in Kubernetes

335 views Asked by At

Problem : I want to implement stickiness on request header called "ORDER_ID". So that if specific order request should be served by specific pod in Kubernetes. But in my case it is not working as requests are not getting stick to specific pod instead getting distributed to different pods as well.

This is how i have installed Ambassador :

  1. helm repo add datawire https://www.getambassador.io
  2. kubectl create namespace ambassador
  3. helm install ambassador --namespace ambassador datawire/ambassador

Below are yaml files :

Deployment.yml

apiVersion: apps/v1
kind: Deplyment
metadata:
  name: order-service
spec:
  replicas: 2
  selector:
    matchLabels:
      app: order-service
strategy:
  type: RollingUpdate
template:
  metadata:
    labels:
      app: order-service
  spec:
    containers:
      - name: orderservice
        image: xyz.io/orderservice
        imagePullPolicy: Always
        ports:
          - containerPort: 3000
           

2 service.yml

apiVersion: v1
kind: Service
metadata:
  name: order-service
spec:
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
  selector:
    app: order-service

3 mapping.yml

apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: ambassador-backend
spec:
  prefix: /
  service: order-service:3000
  resolver: endpoint
  load_balancer:
    policy: least_request
    header: ORDER_ID

Testing by -

curl --insecure --location --request GET 'http://.../backend/orders' --header 'Content-Type: application/json' --header 'ORDER_ID: 1234'

Is there something which i am missing or doing something wrong?

1

There are 1 answers

0
palash-kulkarni On

To setup stickiness, It needs ingress controller to route request to order-service through Ambassador Load Balancer. Also EndpointResolver is needed for Endpoint level Service Discovery which is being used in mapping for overriding the Ambassador's configuration.

The missing parts are -

  1. ingress.yml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: ambassador
  name: order-service-ingress
spec:
  rules:
    - http:
      paths:
        - path: /v1/orders/*
          backend:
            serviceName: order-service
            servicePort: 4000
  1. endpoint_resolver.yml
apiVersion: getambassador.io/v2
kind: KubernetesEndpointResolver
metadata:
  name: endpoint