备考ICA----Istio实验6---流量镜像 Traffic Mirroring 实验

备考ICA----Istio实验6---流量镜像 Traffic Mirroring 实验

流量镜像功能可以将生产的流量镜像拷贝到测试集群或者新的测试版本中,在不影响实际生产环境的情况下,测试具有实际生产流量的服务,帮助减低版本变更的风险。也可以用在不同集群间的同步

1. 部署httpbin应用

1.1 v1版本deployment

v1和v2一样拥有标签 app: httpbin ,同时拥有不同的version: v1标签

mirrors-httpbin-v1.yaml

yaml 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin-v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
      version: v1
  template:
    metadata:
      labels:
        app: httpbin
        version: v1
    spec:
      containers:
      - image: docker.io/kennethreitz/httpbin
        imagePullPolicy: IfNotPresent
        name: httpbin
        command: ["gunicorn", "--access-logfile", "-", "-b", "0.0.0.0:80", "httpbin:app"]
        ports:
        - containerPort: 80

1.2 v2版本deployment

v2和v1一样拥有标签 app: httpbin ,同时拥有不同的version: v2标签

mirrors-httpbin-v2.yaml

yaml 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpbin-v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpbin
      version: v2
  template:
    metadata:
      labels:
        app: httpbin
        version: v2
    spec:
      containers:
      - image: docker.io/kennethreitz/httpbin
        imagePullPolicy: IfNotPresent
        name: httpbin
        command: ["gunicorn", "--access-logfile", "-", "-b", "0.0.0.0:80", "httpbin:app"]
        ports:
        - containerPort: 80

1.3 Service

service 通过标签 app: httpbin 关联 httpbin-v1 和 httpbin-v2

mirrors-httpbin-service.yaml

yaml 复制代码
apiVersion: v1
kind: Service
metadata:
  name: httpbin
  labels:
    app: httpbin
spec:
  ports:
  - name: http
    port: 8000
    targetPort: 80
  selector:
    app: httpbin

1.4 测试容器sleep

sleep 用于测试

mirrors-sleep.yaml

yaml 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sleep
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sleep
  template:
    metadata:
      labels:
        app: sleep
    spec:
      containers:
      - name: sleep
        image: curlimages/curl
        command: ["/bin/sleep","3650d"]
        imagePullPolicy: IfNotPresent

部署以上deployment和svc

bash 复制代码
kubectl apply -f Traffic-Mirroring/mirrors-httpbin-v1.yaml
kubectl apply -f Traffic-Mirroring/mirrors-httpbin-v2.yaml
kubectl apply -f Traffic-Mirroring/mirrors-httpbin-service.yaml
kubectl apply -f Traffic-Mirroring/mirrors-sleep.yaml

2. 配置路由

2.1 所有流量到v1

2.1.1 部署dr和vs

Traffic-Mirroring/mirrors-httpbin-vs-dr.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
spec:
  hosts:
    - httpbin
  http:
  - route:
    - destination:
        host: httpbin
        subset: v1
      weight: 100
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

部署dr和vs

bash 复制代码
kubectl apply -f Traffic-Mirroring/mirrors-httpbin-vs-dr.yaml

2.1.2 测试访问

通过sleep容器向httpbin发起访问

bash 复制代码
kubectl exec deployments/sleep -- curl -sS http://httpbin:8000/headers

由于所有流量都被发给v1,所以v1有一条访问记录,而v2没有

bash 复制代码
kubectl logs deployments/httpbin-v1
kubectl logs deployments/httpbin-v2

2.2 将v1的流量全部镜像给v2

2.2.1 部署vs

将v1所有的流量镜像给v2版本

Traffic-Mirroring/mirrors-httpbin-v1-2-v2.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
spec:
  hosts:
    - httpbin
  http:
  - route:
    - destination:
        host: httpbin
        subset: v1
      weight: 100
    mirror:
      host: httpbin
      subset: v2
    mirrorPercentage:
      value: 100.0

部署vs

bash 复制代码
kubectl apply -f Traffic-Mirroring/mirrors-httpbin-v1-2-v2.yaml

2.2.2 测试访问

通过sleep容器向httpbin发起访问

bash 复制代码
kubectl exec deployments/sleep -- curl -sS http://httpbin:8000/headers

由于所有流量都被发给v1并且镜像给了v2,所以v1有一条访问记录,v2在同一时间也有一条相同的访问记录

bash 复制代码
kubectl logs deployments/httpbin-v1
kubectl logs deployments/httpbin-v2

至此Istio的流量镜像 Traffic Mirroring 实验完成.

相关推荐
野猪佩挤1 小时前
minio作为K8S后端存储
云原生·容器·kubernetes
福大大架构师每日一题8 小时前
6.4 k8s的informer机制
云原生·容器·kubernetes
炸鸡物料库9 小时前
Kubernetes 使用 Kube-Prometheus 构建指标监控 +飞书告警
运维·云原生·kubernetes·飞书·prometheus·devops
ITPUB-微风9 小时前
云原生DevOps:Zadig架构设计与企业实践分析
运维·云原生·devops
IT闫10 小时前
【Dubbo+Zookeeper】——SpringBoot+Dubbo+Zookeeper知识整合
分布式·zookeeper·云原生·dubbo
桂月二二11 小时前
基于eBPF的零信任API网关:重塑云原生时代的安全通信范式
安全·云原生
Karoku06611 小时前
【CI/CD】持续集成及 Jenkins
运维·ci/cd·docker·云原生·容器·kubernetes·jenkins
KTKong19 小时前
kubeadm拉起的k8s集群证书过期的做法集群已奔溃也可以解决
云原生·容器·kubernetes
呱牛do it21 小时前
【系列专栏】银行IT的云原生架构-混合云弹性架构 13
微服务·云原生·金融·架构
阿里云云原生1 天前
IDEA + 通义灵码AI程序员:快速构建DDD后端工程模板
云原生