In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the grayscale release based on nginx-ingress in K8s? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Suppose that in the frontline environment, we already have a set of service app-old to provide 7-tier services, and at this time we fix some problems and need to release a new version of app-new in grayscale, but we do not want to simply switch all client traffic to the new version of app-new directly, but we want to switch only 20% of the traffic to the new version of app-new to be stable for a period of time. After all the traffic is switched to the app-new service, the app-old service is dropped smoothly.
For the above different application release requirements, K8S Ingress Controller supports a variety of traffic segmentation methods:
Traffic segmentation based on Request Header, suitable for grayscale publishing and AB test scenarios
Traffic segmentation based on Cookie, suitable for grayscale publishing and AB test scenarios
Traffic segmentation based on Query Param, suitable for grayscale publishing and AB test scenarios
Traffic segmentation based on service weight, suitable for blue-green publishing scenarios
The following test is based on traffic segmentation based on service weight, and you can also change nginx.ingress.kubernetes.io/canary-weight: "30" to header-based traffic segmentation.
Prepare the old version of the program
The old version of the program app-old
App-old.yaml
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: app-oldspec: replicas: 2 selector: matchLabels: run: app-old template: metadata: labels: run: app-oldspec: containers:-image: zouhl/app:v2.1 imagePullPolicy: Always name: app-old ports:-containerPort: 80 protocol: TCP restartPolicy: Always---apiVersion: v1kind: Servicemetadata: name: app-oldspec: ports:-port: 80 protocol: TCP targetPort: 80 selector: run: app-old sessionAffinity: None type: NodePor
ApiVersion: extensions/v1beta1 kind: Deployment metadata: name: app-old spec: replicas: 2 selector: matchLabels: run: app-old template: metadata: labels: run: app-old spec: containers:-image: zouhl/app:v2.1 imagePullPolicy: Always name: app-old ports:-containerPort: 80 protocol: TCP restartPolicy: Always-- apiVersion: v1 kind: Service metadata: name: app-old spec: ports:-port: 80 protocol: TCP targetPort: 80 selector: run: app-old sessionAffinity: None type: NodePor
The old version of ingress
App-v1.yaml
ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-app labels: app: my-app annotations: kubernetes.io/ingress.class: nginx namespace: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: serviceName: app-old servicePort: 80 path: /
ApiVersion: extensions/v1beta1 kind: Ingress metadata: name: my-app labels: app: my-app annotations: kubernetes.io/ingress.class: nginx namespace: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: serviceName: app-old servicePort: 80 path: /
Create in k8s
Kubectl create-f app-old.yamlkubectl create-f app-v1.yaml
Kubectl create-f app-old.yaml kubectl create-f app-v1.yaml
Equip with a new version of the program
New version of app-new.yaml
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: app-newspec: replicas: 2 selector: matchLabels: run: app-new template: metadata: labels: run: app-newspec: containers:-image: zouhl/app:v2.2 imagePullPolicy: Always name: app-new ports:-containerPort: 80 protocol: TCP restartPolicy: Always---apiVersion: v1kind: Servicemetadata: name: app-newspec: ports:-port: 80 protocol: TCP targetPort: 80 selector: run: app-new sessionAffinity: None type: NodePort
ApiVersion: extensions/v1beta1 kind: Deployment metadata: name: app-new spec: replicas: 2 selector: matchLabels: run: app-new template: metadata: labels: run: app-new spec: containers:-image: zouhl/app:v2.2 imagePullPolicy: Always name: app-new ports:-containerPort: 80 protocol: TCP restartPolicy: Always-- apiVersion: v1 kind: Service metadata: name: app-new spec: ports:-port: 80 protocol: TCP targetPort: 80 selector: run: app-new sessionAffinity: None type: NodePort
New version of canary-ingress
App-v2-canary.yaml
ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-app-canary labels: app: my-app annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/canary: "true" nginx.ingress.kubernetes.io/canary-weight: "30" namespace: defaultspec: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: ServiceName: app-new servicePort: 80 path: /
ApiVersion: extensions/v1beta1 kind: Ingress metadata: name: my-app-canary labels: app: my-app annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/canary: "true" nginx.ingress.kubernetes.io/canary-weight: "30" namespace: default spec: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: serviceName: app-new servicePort: 80 path: /
New version of ingress yaml
App-v2.yaml
ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-app labels: app: my-app annotations: kubernetes.io/ingress.class: nginx namespace: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: serviceName: app-new servicePort: 80 path: /
ApiVersion: extensions/v1beta1 kind: Ingress metadata: name: my-app labels: app: my-app annotations: kubernetes.io/ingress.class: nginx namespace: rules:-host: test.192.168.2.20.xip.io http: paths:-backend: serviceName: app-new servicePort: 80 path: /
Publishing process $tree. ├── app-new.yaml ├── app-old.yaml ├── app-v1.yaml ├── app-v2-canary.yaml └── app-v2.yaml
$tree. ├── app-new.yaml ├── app-old.yaml ├── app-v1.yaml ├── app-v2-canary.yaml └── app-v2.yaml
App-v1 has been released, and now the second version is released in grayscale, with a weight of 30% dint nginx.ingress.kubernetes.iogray: "30". For more parameters, please see github.
Kubectl create-f app-new.yamlkubectl create-f app-v2-canary.yaml
Kubectl create-f app-new.yaml kubectl create-f app-v2-canary.yaml
Check
$kubectl get ingresses.extensions NAME HOSTS ADDRESS PORTS AGEapp-ingress www.example.com 80 109mmy-app test.192.168.2.20.xip.io 80 25mmy-app-canary test.192.168.2.20.xip.io 80 1snginx-test nginx.192.168 .2.20.xip.io 80 3h22m
$kubectl get ingresses.extensions NAME HOSTS ADDRESS PORTS AGE app-ingress www.example.com 80 109m my-app test.192.168.2.20.xip.io 80 25m my-app-canary test.192.168.2.20.xip.io 80 1s nginx-test nginx.192.168.2.20.xip.io 80 3h22m
Observe in the background, 70% to v1, 30% to v2
$while sleep 0.5; do curl "test.192.168.2.20.xip.io"; echo; done {"v2.2 hostname": "app-new-658dfc9c6b-lbmvr"} {"v2.2 hostname": "app-new-658dfc9c6b-qhwtg"} {"v1 hostname": "app-old-64fd44b699- 4hvlb"} {"v1 hostname": "app-old-64fd44b699-zb58f"}
$while sleep 0.5; do curl "test.192.168.2.20.xip.io"; echo; done {"v2.2 hostname": "app-new-658dfc9c6b-lbmvr"} {"v2.2 hostname": "app-new-658dfc9c6b-qhwtg"} {"v1 hostname": "app-old-64fd44b699- 4hvlb"} {"v1 hostname": "app-old-64fd44b699-zb58f"}
If everything is all right, it can be officially released.
# delete the canary ingresskubectl delete-f app-v2-canary.yaml# set 100% traffic to v2kubectl apply-f app-v2.yaml
# delete the canary ingress kubectl delete-f app-v2-canary.yaml # set 100% traffic to v2 kubectl apply-f app-v2.yaml
Check ingress
$kubectl get ingresses.extensions NAME HOSTS ADDRESS PORTS AGEapp-ingress www.example.com 80 109mmy-app test.192.168.2.20.xip.io 80 25mnginx-test nginx.192.168.2.20.xip.io 80 3h23m $while sleep 0.5; do curl "test.192.168.2.20.xip.io"; echo Done {"v2.2 hostname": "app-new-658dfc9c6b-lbmvr"} {"v2.2 hostname": "app-new-658dfc9c6b-qhwtg"}
$kubectl get ingresses.extensions NAME HOSTS ADDRESS PORTS AGE app-ingress www.example.com 80 109m my-app test.192.168.2.20.xip.io 80 25m nginx-test nginx.192.168.2.20.xip.io 80 3h23m $while sleep 0.5; do curl "test.192.168.2.20.xip.io"; echo; done {"v2.2 hostname": "app-new-658dfc9c6b-lbmvr"} {"v2.2 hostname": "app-new-658dfc9c6b-qhwtg"}
After reading the above, have you mastered the method of grayscale publishing based on nginx-ingress in K8s? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 231
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.