Направление трафика на конкретную версию сервиса
Для начала необходимо создать Deployment новой версии приложения (версия docker image не влияет на версию самого
Deployment):
Deployment.yml type=yamlapiVersion: apps/v1 kind: Deployment metadata: name: istio-integration-producer-v2 spec: selector: matchLabels: app: istio-integration-producer replicas: 1 template: metadata: labels: app: istio-integration-producer version: v2 annotations: sidecar.istio.io/inject: 'true' spec: containers: - name: istio-integration-producer image: http://URL_Docker_Registry/istio-integration-producer:0.1.0.1
После добавим необходимые правила для VirtualService, в нашем случае это будут все пользователи, которые передают в
cookie свой email, а также обновим subsets в DestinationRule:
VirtualService.yml type=yamlapiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: istio-integration-producer spec: exportTo: - . gateways: - ingress-gateway hosts: - istio-integration-namespace.tech http: - match: - headers: cookie: regex: '^(.*?;)?(email=[^;]*@some-company-name.com)(;.*)?$' uri: prefix: /api/istio-integration/producer name: istio-integration-producer-test route: - destination: host: istio-integration-producer port: number: 8080 subset: v2 - match: - uri: prefix: /api/istio-integration/producer name: istio-integration-producer-stable route: - destination: host: istio-integration-producer port: number: 8080 subset: v1
DestinationRule.yml type=ymlapiVersion: networking.istio.io/v1beta1 kind: DestinationRule metadata: name: istio-integration-producer spec: host: istio-integration-producer subsets: - labels: version: v1 name: v1 - labels: version: v2 name: v2
Для начала необходимо создать и запустить 2-е версии 1-го микросервиса (consumer):
Deployment.yml type=yamlapiVersion: apps/v1 kind: Deployment metadata: name: istio-integration-consumer-v1 spec: selector: matchLabels: app: istio-integration-consumer replicas: 1 template: metadata: labels: app: istio-integration-consumer version: v1 annotations: sidecar.istio.io/inject: 'true' spec: containers: - name: istio-integration-consumer image: http://URL_Docker_Registry/istio-integration-consumer:0.1.0.1 ports: - containerPort: 8090
Deployment.yml type=yamlapiVersion: apps/v1 kind: Deployment metadata: name: istio-integration-consumer-v2 spec: selector: matchLabels: app: istio-integration-consumer replicas: 1 template: metadata: labels: app: istio-integration-consumer version: v2 annotations: sidecar.istio.io/inject: 'true' spec: containers: - name: istio-integration-consumer image: http://URL_Docker_Registry/istio-integration-consumer:0.1.0.1 ports: - containerPort: 8090
Далее необходимо настроить VirtualService и DestinationRule, версия необходимого сервиса будет определяться с помощью
хэддера Target-Service-Version.
VirtualService.yml type=yamlapiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: istio-integration-consumer-iternal spec: exportTo: - . hosts: - istio-integration-consumer.namespace.svc.cluster.local http: - name: istio-integration-consumer-stable match: - headers: target-service-version: exact: 0.1.0.1 uri: prefix: /api/istio-integration/consumer route: - destination: host: istio-integration-consumer port: number: 8090 subset: v1 - name: istio-integration-consumer-test match: - headers: target-service-version: exact: 0.1.0.2 uri: prefix: /api/istio-integration/consumer route: - destination: host: istio-integration-consumer port: number: 8090 subset: v2
DestinationRule.yml type=yamlapiVersion: networking.istio.io/v1beta1 kind: DestinationRule metadata: name: istio-integration-producer spec: host: istio-integration-producer subsets: - labels: version: v1 name: v1 - labels: version: v2 name: v2
Теперь то же самое необходимо сделать с сервисом, который будет отправлять запросы (producer), частично описанный выше.
Deployment.yml type=yamlapiVersion: apps/v1 kind: Deployment metadata: name: istio-integration-producer-v1 spec: selector: matchLabels: app: istio-integration-producer replicas: 1 template: metadata: labels: app: istio-integration-producer version: v1 annotations: sidecar.istio.io/inject: 'true' spec: containers: - name: istio-integration-producer image: http://URL_Docker_Registry/istio-integration-producer:0.1.0.1 env: - name: INTEGRATION_CONSUMER_SCHEMA value: HTTP - name: INTEGRATION_CONSUMER_HOST value: istio-integration-consumer.namespace.svc.cluster.local - name: INTEGRATION_CONSUMER_PORT value: '8090' - name: INTEGRATION_CONSUMER_BASE_PATH value: /api/istio-integration/consumer - name: INTEGRATION_CONSUMER_VERSION value: 0.1.0.1 ports: - containerPort: 8080
Deployment.yml type=yamlapiVersion: apps/v1 kind: Deployment metadata: name: istio-integration-producer-v2 spec: selector: matchLabels: app: istio-integration-producer replicas: 1 template: metadata: labels: app: istio-integration-producer version: v2 annotations: sidecar.istio.io/inject: 'true' spec: containers: - name: istio-integration-producer image: http://URL_Docker_Registry/istio-integration-producer:0.1.0.1 env: - name: INTEGRATION_CONSUMER_SCHEMA value: HTTP - name: INTEGRATION_CONSUMER_HOST value: istio-integration-consumer.namespace.svc.cluster.local - name: INTEGRATION_CONSUMER_PORT value: '8090' - name: INTEGRATION_CONSUMER_BASE_PATH value: /api/istio-integration/consumer - name: INTEGRATION_CONSUMER_VERSION value: 0.1.0.2 ports: - containerPort: 8080