当前位置:网站首页>Grayscale publishing through ingress

Grayscale publishing through ingress

2022-06-11 06:52:00 [email protected]

1、 Deploy Deployment V1 application

Create as follows YAML file (app-v1.yaml)

apiVersion: v1
kind: Service
metadata:
  name: my-app-v1
  labels:
    app: my-app
spec:
  ports:
  - name: http
    port: 80
    targetPort: http
  selector:
    app: my-app
    version: v1.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-v1
  labels:
    app: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
      version: v1.0.0
  template:
    metadata:
      labels:
        app: my-app
        version: v1.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9101"
    spec:
      containers:
      - name: my-app
        image: registry.cn-hangzhou.aliyuncs.com/containerdemo/containersol-k8s-deployment-strategies
        ports:
        - name: http
          containerPort: 8080
        - name: probe
          containerPort: 8086
        env:
        - name: VERSION
          value: v1.0.0
        livenessProbe:
          httpGet:
            path: /live
            port: probe
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ready
            port: probe
          periodSeconds: 5

Execute the following command to deploy Deployement V1 application :

kubectl apply -f app-v1.yaml

Create as follows Ingress YAML file (ingress-v1.yaml)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  rules:
  - host: my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com
    http:
      paths:
      - backend:
          serviceName: my-app-v1
          servicePort: 80
        path: /

Execute the following command to deploy Ingress resources

kubectl apply -f ingress-v1.yaml

Pass... After deployment curl Command to test :

curl my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com

You will see the following return :

Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0

2、 Deploy Deployment V2 application

Create as follows YAML file (app-v2.yaml)

apiVersion: v1
kind: Service
metadata:
  name: my-app-v2
  labels:
    app: my-app
spec:
  ports:
  - name: http
    port: 80
    targetPort: http
  selector:
    app: my-app
    version: v2.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-v2
  labels:
    app: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
      version: v2.0.0
  template:
    metadata:
      labels:
        app: my-app
        version: v2.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9101"
    spec:
      containers:
      - name: my-app
        image: registry.cn-hangzhou.aliyuncs.com/containerdemo/containersol-k8s-deployment-strategies
        ports:
        - name: http
          containerPort: 8080
        - name: probe
          containerPort: 8086
        env:
        - name: VERSION
          value: v2.0.0
        livenessProbe:
          httpGet:
            path: /live
            port: probe
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ready
            port: probe
          periodSeconds: 5

Execute the following command to deploy Deployement V2 application :

kubectl apply -f app-v2.yaml

3、 According to the weight strategy, the gray scale is reduced to Deployment V2 application

Create as follows Ingress YAML file (ingress-v2-canary-weigth.yaml)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app-canary
  labels:
    app: my-app
  annotations:
    # Enable canary and send 10% of traffic to version 2
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-weight: "10"
spec:
  rules:
  - host: my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com
    http:
      paths:
      - backend:
          serviceName: my-app-v2
          servicePort: 80
        path: /

Execute the following command to deploy Ingress resources

kubectl apply -f ingress-v2-canary-weigth.yaml

Execute the following command to test :

while sleep 0.1;do curl my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com; done

The test results are as follows :

Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0
Host: my-app-v2-67c69b8857-g82gr, Version: v2.0.0
Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0

4、 according to Header Policy grayscale to Deployment V2 application

Create as follows Ingress YAML file (ingress-v2-canary-header.yaml)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app-canary
  labels:
    app: my-app
  annotations:
    # Enable canary and send traffic with headder x-app-canary to version 2
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-header: "x-app-canary"
    nginx.ingress.kubernetes.io/canary-by-header-value: "true"
spec:
  rules:
  - host: my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com
    http:
      paths:
      - backend:
          serviceName: my-app-v2
          servicePort: 80

Execute the following command to deploy Ingress resources

kubectl apply -f ingress-v2-canary-header.yaml

adopt curl Command to test the application :

curl my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com

give the result as follows :

At present, the environment is still v1

Host: my-app-v1-68bfcbb7cf-w4rpg, Version: v1.0.0

Execute the following command to publish all grayscale environments to v2

curl my-app-22e6541b324bd1dfe04a48beb40046ea.ca2ef983cc3a64042a32c1a423d32021e.cn-shanghai.alicontainer.com -H "x-app-canary: true"

give the result as follows

Host: my-app-v2-67c69b8857-g82gr, Version: v2.0.0
原网站

版权声明
本文为[[email protected] micro fatty]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110649304443.html