粘性在Kubernetes中的大使的请求标头上不起作用

时间:2020-09-25 23:06:07

标签: azure kubernetes devops kubernetes-ingress ambassador

问题:我想对称为“ ORDER_ID”的请求标头实施粘性。因此,如果特定的订单请求应由Kubernetes中的特定pod服务。但是在我的情况下,它不能正常工作,因为请求没有停留在特定的容器上,而是也分配到了不同的容器上。

这是我安装大使的方式:

  1. 帮助仓库添加数据线https://www.getambassador.io
  2. kubectl创建命名空间大使
  3. helm install大使--namespace大使datawire /大使

以下是yaml文件:

Deployment.yml

text

2 service.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
           

3 mapping.yml

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

测试者-

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

我是否缺少某些东西或做错了什么?

1 个答案:

答案 0 :(得分:0)

要设置粘性,它需要入口控制器通过Ambassador Load Balancer将请求路由到订单服务。端点级服务发现还需要EndpointResolver,该服务在映射中用于覆盖大使的配置。

缺少的部分是-

  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