This commit is contained in:
109
网关/Ingress/通过Ingress实现金丝雀发布.md
Normal file
109
网关/Ingress/通过Ingress实现金丝雀发布.md
Normal file
@@ -0,0 +1,109 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 通过Ingress实现金丝雀发布
|
||||
|
||||
**通过 Ingress 实现基于权重的金丝雀**
|
||||
|
||||
部署测试示例 Nginx Deployment v1和v2
|
||||
|
||||
1. 部署 v1 版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-v1.yaml
|
||||
```
|
||||
|
||||
2. 部署 v2 版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-v2.yaml
|
||||
```
|
||||
|
||||
3. 创建两个 Service
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-deployment-service-1
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
version: v1
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-deployment-service-2
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
version: v2
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
4. 创建 Ingress 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
# 金丝雀 Ingress 对象为 v1 版本
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx-ingress-1
|
||||
namespace: default
|
||||
spec:
|
||||
rules:
|
||||
- host: example.com # 替换为你的域名
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: nginx-deployment-service-1
|
||||
port:
|
||||
number: 80
|
||||
tls:
|
||||
- hosts:
|
||||
- example.com # 替换为你的域名
|
||||
secretName: example-tls # 替换为你的证书
|
||||
---
|
||||
# 金丝雀 Ingress 对象为 v2 版本
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx-ingress-2
|
||||
namespace: default
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/canary: "true"
|
||||
nginx.ingress.kubernetes.io/canary-weight: "10" # 10%流量到金丝雀
|
||||
spec:
|
||||
rules:
|
||||
- host: example.com # 替换为你的域名
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: nginx-deployment-service-2
|
||||
port:
|
||||
number: 80
|
||||
tls:
|
||||
- hosts:
|
||||
- example.com # 替换为你的域名
|
||||
secretName: example-tls # 替换为你的证书
|
||||
EOF
|
||||
```
|
||||
|
||||
5. 慢慢调整 Nginx-Ingress-2 流量到 100%,即可完成更新
|
||||
|
||||
Reference in New Issue
Block a user