Janrs.com | 杨建勇

  • 首页
  • 站点地图
  • 所有文章
  • 加入学习群
Janrs.com | 杨建勇
Go/Kubernetes/Istio/CloudNative
  1. 首页
  2. k8s/云原生
  3. Istio
  4. 正文

istio实现多版本流量转移

2023年3月16日 18点热度 0人点赞 0条评论

istio实现多版本流量转移

多版本流量分发主要概念:同一个服务部署多个 deployment 共用一个 service 。通过在 deployment 设置 version 然后在 virtual service 以及 destination 配置流量转发。


deploy 配置示例


apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-client
  namespace: rakour-dev
  labels:
    app: hello-client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-client
  template:
    metadata:
      labels:
        app: hello-client
        version: v1
    spec:
      imagePullSecrets:
        - name: registry-secret
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
      containers:
        - name: hello-client
          image: REGISTRY_URL/PROJECT_NAME/IMAGE_NAME:IMAGE_VERSION
          imagePullPolicy: Always
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: timezone
              mountPath: /etc/localtime
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-client-v2
  namespace: rakour-dev
  labels:
    app: hello-client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-client
  template:
    metadata:
      labels:
        app: hello-client
        version: v2
    spec:
      imagePullSecrets:
        - name: registry-secret
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
      containers:
        - name: hello-client
          image: REGISTRY_URL/PROJECT_NAME/IMAGE_NAME:IMAGE_VERSION
          imagePullPolicy: Always
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: timezone
              mountPath: /etc/localtime
---
# service
apiVersion: v1
kind: Service
metadata:
  name: hello-client
  namespace: rakour-dev
spec:
  type: ClusterIP
  selector:
    app: hello-client
  ports:
    - port: 9090
      protocol: TCP
      targetPort: 9090

#yaml

gateway 配置示例


apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: rpc
  namespace: rakour-dev
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - rpc.api.rakour.com
      port:
        name: http
        number: 80
        protocol: HTTP

#bash

virtual service 配置示例


apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: rpc
  namespace: rakour-dev
spec:
  gateways:
    - rpc
  hosts:
    - rpc.api.rakour.com
  http:
    - route:
        - destination:
            host: hello-client
            subset: v1
          weight: 50
        - destination:
            host: hello-client
            subset: v2
          weight: 50

destination 配置示例


apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: hello-client
  namespace: rakour-dev
spec:
  host: hello-client
  subsets:
    - labels:
        version: v2
      name: v2
    - labels:
        version: v1
      name: v1
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
#bash
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: grpc istio 云原生CloudNative 微服务
最后更新:2023年3月16日

码仔

Janrs.com

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
有关Go/istio/k8s/云原生直接搜
文章目录
  • istio实现多版本流量转移
    • deploy 配置示例
    • gateway 配置示例
    • virtual service 配置示例
    • destination 配置示例

COPYRIGHT © 2023 Janrs.com | 杨建勇. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

闽ICP备20002184号