apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: site-gw
  namespace: default  # 指定为 ingress gateway pod 所在的 namespace
spec:
  selector:
    app: istio-ingressgateway  # ingressgateway 的 labels
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "site.kb.cx"
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: site-svc-vs
spec:
  hosts:
  - "site.kb.cx"  # 对应 Gateway/site-gw
  gateways:
  - default/site-gw  # 指定 Ingress Gateway
  http:
  - name: canary
    match:
    - headers:
        x-canary:
          exact: "true"
    route:
    - destination:
        host: site
        subset: v11
      headers:
        request:
          set:
            User-Agent: Chrome
        response:
          add:
            x-canary: "true"
  - name: default
    headers:
      response:
        add:
          version: "v10"
    route:
    - destination:
        host: site
        subset: v10

---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: site
spec:
  host: site
  subsets:
  - name: v10
    labels:
      app: site
      version: v1.0
  - name: v11
    labels:
      app: site
      version: v1.1
---
apiVersion: v1
kind: Service
metadata:
  name: site
  labels:
    app: site
spec:
  ports:
  - port: 8080
    name: http
  selector:
    app: site
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: site-v10
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: site
      version: v1.0
  template:
    metadata:
      name: site
      labels:
        app: site
        version: v1.0
    spec:
      containers:
      - name: site
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-c", "echo 'welcome to site v1.0' > /var/www/index.html; httpd -f -p 8080 -h /var/www"]
        ports:
        - name: http
          containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: site-v11
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: site
      version: v1.1
  template:
    metadata:
      name: site
      labels:
        app: site
        version: v1.1
    spec:
      containers:
      - name: site
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-c", "echo 'welcome to site v1.1' > /var/www/index.html; httpd -f -p 8080 -h /var/www"]
        ports:
        - name: http
          containerPort: 8080
