6. 配置MSE Ingress规则
- 针对入口应用A,配置两个K8s Service,复制以下配置,点击网络 > 服务 > 使用YAML创建资源。
apiVersion: v1 kind: Service metadata: name: spring-cloud-a-base namespace: default spec: ports: - name: http port: 20001 protocol: TCP targetPort: 20001 selector: app: spring-cloud-a --- apiVersion: v1 kind: Service metadata: name: spring-cloud-a-gray namespace: default spec: ports: - name: http port: 20001 protocol: TCP targetPort: 20001 selector: app: spring-cloud-a-gray
- 这里假设业务域名为example.com,访问example.com的请求流量只通过基线环境(线上环境),点击网络 > 路由 > 使用YAML创建资源,配置以下基线环境的Ingress规则。
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: spring-cloud-a namespace: default spec: ingressClassName: mse rules: - host: example.com http: paths: - backend: service: name: spring-cloud-a-base port: number: 20001 path: / pathType: Prefix
- 假设这里基于Header策略来区分线上正式流量和灰度流量,希望带有HTTP Header为x-user-id: 100的请求流量,访问example.com路由到灰度环境中,流量会优先访问链路中各个应用对应的灰度版本,若无灰度版本,则会容灾到基线版本。配置以下灰度环境的Ingress规则:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: nginx.ingress.kubernetes.io/canary: 'true' nginx.ingress.kubernetes.io/canary-by-header: x-user-id nginx.ingress.kubernetes.io/canary-by-header-value: '100' mse.ingress.kubernetes.io/request-header-control-update: x-mse-tag gray name: spring-cloud-a-gray namespace: default spec: ingressClassName: mse rules: - host: example.com http: paths: - backend: service: name: spring-cloud-a-gray port: number: 20001 path: / pathType: Prefix