{"id":1162,"date":"2022-07-06T16:57:04","date_gmt":"2022-07-06T08:57:04","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1162"},"modified":"2023-04-07T09:55:08","modified_gmt":"2023-04-07T01:55:08","slug":"kubernetes-uses-nginx-ingress-to-implement-blue-green","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2022\/07\/kubernetes-uses-nginx-ingress-to-implement-blue-green\/","title":{"rendered":"Kubernetes \u4f7f\u7528Nginx-Ingress\u5b9e\u73b0\u84dd\u7eff\u53d1\u5e03\/\u91d1\u4e1d\u96c0\u53d1\u5e03\/AB\u6d4b\u8bd5"},"content":{"rendered":"
\n\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5728\u4f7f\u7528Kubernetes\u4f5c\u4e3a\u4e1a\u52a1\u5e94\u7528\u7684\u4e91\u5e73\u53f0\uff0c\u60f3\u8981\u5b9e\u73b0\u5e94\u7528\u7684\u84dd\u7eff\u90e8\u7f72\u7528\u6765\u8fed\u4ee3\u5e94\u7528\u7248\u672c\uff0c\u7528lstio\u592a\u91cd\u592a\u590d\u6742\uff0c\u800c\u4e14\u5b83\u672c\u8eab\u5b9a\u4f4d\u4e8e\u6d41\u63a7\u548c\u7f51\u683c\u6cbb\u7406\uff1bIngress-Nginx\u57280.21\u7248\u672c\u5f15\u5165\u4e86Canary\u529f\u80fd\uff0c\u53ef\u4ee5\u4e3a\u7f51\u5173\u5165\u53e3\u914d\u7f6e\u591a\u4e2a\u7248\u672c\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u7528annotation\u6765\u63a7\u5236\u591a\u4e2a\u540e\u7aef\u670d\u52a1\u7684\u6d41\u91cf\u5206\u914d<\/p>\n<\/blockquote>\n
Ingress-Nginx-Annotation Canary \u529f\u80fd\u4ecb\u7ecd<\/h2>\n
\n\u5982\u679c\u60f3\u542f\u7528Canary\u529f\u80fd\uff0c\u8981\u5148\u8bbe\u7f6e
nginx.ingress.kubernetes.io\/canary: "true"<\/code>\uff0c\u7136\u540e\u53ef\u4ee5\u542f\u7528\u4ee5\u4e0b\u6ce8\u91ca\u6765\u914d\u7f6eCanary<\/p>\n<\/blockquote>\n
\n
nginx.ingress.kubernetes.io\/canary-weight<\/code> \u8bf7\u6c42\u5230Canary ingress\u4e2d\u6307\u5b9a\u7684\u670d\u52a1\u7684\u8bf7\u6c42\u767e\u5206\u6bd4\uff0c\u503c\u4e3a0-100\u7684\u6574\u6570\uff0c\u6839\u636e\u8bbe\u7f6e\u7684\u503c\u6765\u51b3\u5b9a\u5927\u6982\u6709\u767e\u5206\u4e4b\u591a\u5c11\u7684\u6d41\u91cf\u4f1a\u5206\u914dCanary Ingress\u4e2d\u6307\u5b9a\u7684\u540e\u7aefs\u670d\u52a1<\/li>\n
nginx.ingress.kubernetes.io\/canary-by-header<\/code> \u57fa\u4e8erequest header \u7684\u6d41\u91cf\u5207\u5206\uff0c\u9002\u7528\u4e8e\u7070\u5ea6\u53d1\u5e03\u6216\u8005A\/B\u6d4b\u8bd5\uff0c\u5f53\u8bbe\u5b9a\u7684hearder\u503c\u4e3aalways\u662f\uff0c\u8bf7\u6c42\u6d41\u91cf\u4f1a\u88ab\u4e00\u76f4\u5206\u914d\u5230Canary\u5165\u53e3\uff0c\u5f53hearder\u503c\u88ab\u8bbe\u7f6e\u4e3anever\u65f6\uff0c\u8bf7\u6c42\u6d41\u91cf\u4e0d\u4f1a\u5206\u914d\u5230Canary\u5165\u53e3\uff0c\u5bf9\u4e8e\u5176\u4ed6hearder\u503c\uff0c\u5c06\u5ffd\u7565\uff0c\u5e76\u901a\u8fc7\u4f18\u5148\u7ea7\u5c06\u8bf7\u6c42\u6d41\u91cf\u5206\u914d\u5230\u5176\u4ed6\u89c4\u5219<\/li>\n
nginx.ingress.kubernetes.io\/canary-by-header-value<\/code> \u8fd9\u4e2a\u914d\u7f6e\u8981\u548c
nginx.ingress.kubernetes.io\/canary-by-header<\/code> \u4e00\u8d77\u4f7f\u7528\uff0c\u5f53\u8bf7\u6c42\u4e2d\u7684hearder key\u548cvalue \u548c
nginx.ingress.kubernetes.io\/canary-by-header<\/code>
nginx.ingress.kubernetes.io\/canary-by-header-value<\/code>\u5339\u914d\u65f6\uff0c\u8bf7\u6c42\u6d41\u91cf\u4f1a\u88ab\u5206\u914d\u5230Canary Ingress\u5165\u53e3\uff0c\u5bf9\u4e8e\u5176\u4ed6\u4efb\u4f55hearder\u503c\uff0c\u5c06\u5ffd\u7565\uff0c\u5e76\u901a\u8fc7\u4f18\u5148\u7ea7\u5c06\u8bf7\u6c42\u6d41\u91cf\u5206\u914d\u5230\u5176\u4ed6\u89c4\u5219<\/li>\n
nginx.ingress.kubernetes.io\/canary-by-cookie<\/code> \u8fd9\u4e2a\u914d\u7f6e\u662f\u57fa\u4e8ecookie\u7684\u6d41\u91cf\u5207\u5206\uff0c\u4e5f\u9002\u7528\u4e8e\u7070\u5ea6\u53d1\u5e03\u6216\u8005A\/B\u6d4b\u8bd5\uff0c\u5f53cookie\u503c\u8bbe\u7f6e\u4e3aalways\u65f6\uff0c\u8bf7\u6c42\u6d41\u91cf\u5c06\u88ab\u8def\u7531\u5230Canary Ingress\u5165\u53e3\uff0c\u5f53cookie\u503c\u8bbe\u7f6e\u4e3anever\u65f6\uff0c\u8bf7\u6c42\u6d41\u91cf\u5c06\u4e0d\u4f1a\u8def\u7531\u5230Canary\u5165\u53e3\uff0c\u5bf9\u4e8e\u5176\u4ed6\u503c\uff0c\u5c06\u5ffd\u7565\uff0c\u5e76\u901a\u8fc7\u4f18\u5148\u7ea7\u5c06\u8bf7\u6c42\u6d41\u91cf\u5206\u914d\u5230\u5176\u4ed6\u89c4\u5219<\/li>\n<\/ul>\n
\n\u91d1\u4e1d\u96c0\u89c4\u5219\u6309\u4f18\u5148\u987a\u5e8f\u8fdb\u884c\u5982\u4e0b\u6392\u5e8f\uff1acanary-by-header - > canary-by-cookie - > canary-weight<\/p>\n<\/blockquote>\n
1.\u57fa\u4e8e\u6743\u91cd\u7684\u5c0f\u89c4\u6a21\u7248\u672c\u6d4b\u8bd5<\/h3>\n
\n
- v1\u7248\u672c\u7f16\u6392\u6587\u4ef6<\/li>\n<\/ul>\n
apiVersion: extensions\/v1beta1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n labels:\n app: echoserverv1\n name: echoserverv1\n namespace: echoserver\nspec:\n rules:\n - host: echo.chulinx.com\n http:\n paths:\n - backend:\n serviceName: echoserverv1\n servicePort: 8080\n path: \/\n---\nkind: Service\napiVersion: v1\nmetadata:\n name: echoserverv1\n namespace: echoserver\nspec:\n selector:\n name: echoserverv1\n type: ClusterIP\n ports:\n - name: echoserverv1\n port: 8080\n targetPort: 8080\n---\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n name: echoserverv1\n namespace: echoserver\n labels:\n name: echoserverv1\nspec:\n template:\n metadata:\n labels:\n name: echoserverv1\n spec:\n containers:\n - image: mirrorgooglecontainers\/echoserver:1.10\n name: echoserverv1 \n ports:\n - containerPort: 8080\n name: echoserverv1<\/code><\/pre>\n
\n
- \u67e5\u770bv1\u7248\u672c\u521b\u5efa\u7684\u8d44\u6e90<\/li>\n<\/ul>\n
$ [K8sSj] kubectl get pod,service,ingress -n echoserver\nNAME READY STATUS RESTARTS AGE\npod\/echoserverv1-657b966cb5-7grqs 1\/1 Running 0 24h\n\nNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE\nservice\/echoserverv1 ClusterIP 10.99.68.72 <none> 8080\/TCP 24h\n\nNAME HOSTS ADDRESS PORTS AGE\ningress.extensions\/echoserverv1 echo.chulinx.com 80 24h<\/code><\/pre>\n
\n
- \u8bbf\u95eev1\u7684\u670d\u52a1,\u53ef\u4ee5\u770b\u523010\u4e2a\u8bf7\u6c42\u90fd\u662f\u8bbf\u95ee\u5230\u4e00\u4e2apod\u4e0a\u4e5f\u5c31\u662fv1\u7248\u672c\u7684\u670d\u52a1<\/li>\n<\/ul>\n
$ [K8sSj] for i in `seq 10`;do curl -s echo.chulinx.com|grep Hostname;done\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs<\/code><\/pre>\n
\n
- \u521b\u5efav2\u7248\u672c\u7684\u670d\u52a1<\/li>\n<\/ul>\n
\n\u6211\u4eec\u5f00\u542fcanary\u529f\u80fd\uff0c\u5c06v2\u7248\u672c\u7684\u6743\u91cd\u8bbe\u7f6e\u4e3a50%,\u8fd9\u4e2a\u767e\u5206\u6bd4\u5e76\u4e0d\u80fd\u7cbe\u786e\u7684\u5c06\u8bf7\u6c42\u5e73\u5747\u5206\u914d\u5230\u4e24\u4e2a\u7248\u672c\u7684\u670d\u52a1\uff0c\u800c\u662f\u572850%\u4e0a\u4e0b\u6d6e\u52a8<\/p>\n<\/blockquote>\n
apiVersion: extensions\/v1beta1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n nginx.ingress.kubernetes.io\/canary: "true"\n nginx.ingress.kubernetes.io\/canary-weight: "50"\n labels:\n app: echoserverv2\n name: echoserverv2\n namespace: echoserver\nspec:\n rules:\n - host: echo.chulinx.com\n http:\n paths:\n - backend:\n serviceName: echoserverv2\n servicePort: 8080\n path: \/\n---\nkind: Service\napiVersion: v1\nmetadata:\n name: echoserverv2\n namespace: echoserver\nspec:\n selector:\n name: echoserverv2\n type: ClusterIP\n ports:\n - name: echoserverv2\n port: 8080\n targetPort: 8080\n---\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n name: echoserverv2\n namespace: echoserver\n labels:\n name: echoserverv2\nspec:\n template:\n metadata:\n labels:\n name: echoserverv2\n spec:\n containers:\n - image: mirrorgooglecontainers\/echoserver:1.10\n name: echoserverv2 \n ports:\n - containerPort: 8080\n name: echoserverv2<\/code><\/pre>\n
\n
- \u518d\u6b21\u67e5\u770b\u521b\u5efa\u7684\u8d44\u6e90<\/li>\n<\/ul>\n
$ [K8sSj] kubectl get pod,service,ingress -n echoserver\nNAME READY STATUS RESTARTS AGE\npod\/echoserverv1-657b966cb5-7grqs 1\/1 Running 0 24h\npod\/echoserverv2-856bb5758-f9tqn 1\/1 Running 0 4s\n\nNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE\nservice\/echoserverv1 ClusterIP 10.99.68.72 <none> 8080\/TCP 24h\nservice\/echoserverv2 ClusterIP 10.111.103.170 <none> 8080\/TCP 4s\n\nNAME HOSTS ADDRESS PORTS AGE\ningress.extensions\/echoserverv1 echo.chulinx.com 80 24h\ningress.extensions\/echoserverv2 echo.chulinx.com 80 4s<\/code><\/pre>\n
\n
- \u8bbf\u95ee\u6d4b\u8bd5<\/li>\n<\/ul>\n
\n\u53ef\u4ee5\u770b\u5230\u8bf7\u6c42\u67094\u4e2a\u843d\u5230v2\u7248\u672c\uff0c6\u4e2a\u843d\u5230v1\u7248\u672c\uff0c\u7406\u8bba\u4e0a\u6765\u8bf4\uff0c\u8bf7\u6c42\u8bf4\u8d8a\u591a\uff0c\u843d\u5230v2\u7248\u672c\u7684\u8bf7\u6c42\u6570\u8d8a\u63a5\u8fd1\u8bbe\u7f6e\u7684\u6743\u91cd50%<\/p>\n<\/blockquote>\n
$ [K8sSj] for i in `seq 10`;do curl -s echo.chulinx.com|grep Hostname;done\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs<\/code><\/pre>\n
2.\u57fa\u4e8eheader\u7684A\/B\u6d4b\u8bd5<\/h3>\n
\n
- \u66f4\u6539v2\u7248\u672c\u7684\u7f16\u6392\u6587\u4ef6<\/li>\n<\/ul>\n
\n\u589e\u52a0header
nginx.ingress.kubernetes.io\/canary-by-header: "v2"<\/code><\/p>\n<\/blockquote>\n
apiVersion: extensions\/v1beta1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n nginx.ingress.kubernetes.io\/canary: "true"\n nginx.ingress.kubernetes.io\/canary-weight: "50"\n nginx.ingress.kubernetes.io\/canary-by-header: "v2"\n labels:\n app: echoserverv2\n name: echoserverv2\n namespace: echoserver\nspec:\n rules:\n - host: echo.chulinx.com\n http:\n paths:\n - backend:\n serviceName: echoserverv2\n servicePort: 8080\n path: \/\n---\nkind: Service\napiVersion: v1\nmetadata:\n name: echoserverv2\n namespace: echoserver\nspec:\n selector:\n name: echoserverv2\n type: ClusterIP\n ports:\n - name: echoserverv2\n port: 8080\n targetPort: 8080\n---\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n name: echoserverv2\n namespace: echoserver\n labels:\n name: echoserverv2\nspec:\n template:\n metadata:\n labels:\n name: echoserverv2\n spec:\n containers:\n - image: mirrorgooglecontainers\/echoserver:1.10\n name: echoserverv2 \n ports:\n - containerPort: 8080\n name: echoserverv2<\/code><\/pre>\n
\n
- \u66f4\u65b0\u8bbf\u95ee\u6d4b\u8bd5<\/li>\n<\/ul>\n
\n\u6d4b\u8bd5\u4e86header \u4e3a
v2:always<\/code>
v2:never<\/code>
v2:true<\/code>\u8fd9\u4e09\u4e2ahearder\u503c\uff0c\u53ef\u4ee5\u770b\u5230\u5f53hearder\u4e3a
v2:always<\/code>\u65f6\uff0c\u6d41\u91cf\u4f1a\u5168\u90e8\u6d41\u5165v2\uff0c\u5f53
v2:never<\/code>\u65f6\uff0c\u6d41\u91cf\u4f1a\u5168\u90e8\u6d41\u5165v1\uff0c\u5f53
v2:true<\/code>\u65f6\uff0c\u4e5f\u5c31\u662f\u975e
always\/never<\/code>,\u6d41\u91cf\u4f1a\u6309\u7167\u914d\u7f6e\u7684\u6743\u91cd\u6d41\u5165\u5bf9\u5e94\u7248\u672c\u7684\u670d\u52a1<\/p>\n<\/blockquote>\n
$ [K8sSj] kubectl apply -f appv2.yml\ningress.extensions\/echoserverv2 configured\nservice\/echoserverv2 unchanged\ndeployment.extensions\/echoserverv2 unchanged\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:always" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:never" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:true" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn<\/code><\/pre>\n
\n
- \u81ea\u5b9a\u4e49header-value<\/li>\n<\/ul>\n
apiVersion: extensions\/v1beta1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n nginx.ingress.kubernetes.io\/canary: "true"\n nginx.ingress.kubernetes.io\/canary-weight: "50"\n nginx.ingress.kubernetes.io\/canary-by-header: "v2"\n nginx.ingress.kubernetes.io\/canary-by-header-value: "true"\n labels:\n app: echoserverv2\n name: echoserverv2\n namespace: echoserver\nspec:\n rules:\n - host: echo.chulinx.com\n http:\n paths:\n - backend:\n serviceName: echoserverv2\n servicePort: 8080\n path: \/\n---\nkind: Service\napiVersion: v1\nmetadata:\n name: echoserverv2\n namespace: echoserver\nspec:\n selector:\n name: echoserverv2\n type: ClusterIP\n ports:\n - name: echoserverv2\n port: 8080\n targetPort: 8080\n---\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n name: echoserverv2\n namespace: echoserver\n labels:\n name: echoserverv2\nspec:\n template:\n metadata:\n labels:\n name: echoserverv2\n spec:\n containers:\n - image: mirrorgooglecontainers\/echoserver:1.10\n name: echoserverv2 \n ports:\n - containerPort: 8080\n name: echoserverv2<\/code><\/pre>\n
\n
- \u66f4\u65b0\u6d4b\u8bd5<\/li>\n<\/ul>\n
\n\u53ef\u4ee5\u770b\u5230\u53ea\u6709header\u4e3a
v2:true<\/code>\u65f6\uff0c\u8bf7\u6c42\u6d41\u91cf\u624d\u4f1a\u6d41\u5165v2\u7248\u672c\uff0c\u5176\u4ed6\u503c\u6d41\u91cf\u90fd\u4f1a\u6309\u7167\u6743\u91cd\u8bbe\u7f6e\u6d41\u5165\u4e0d\u901a\u7248\u672c\u7684\u670d\u52a1<\/p>\n<\/blockquote>\n
$ [K8sSj] kubectl apply -f appv2.yml\ningress.extensions\/echoserverv2 configured\nservice\/echoserverv2 unchanged\ndeployment.extensions\/echoserverv2 unchanged\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:true" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:always" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\n\n$ [K8sSj] for i in `seq 10`;do curl -s -H "v2:never" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs<\/code><\/pre>\n
3.\u57fa\u4e8ecookie\u7684\u6d41\u63a7<\/h3>\n
\ncookie\u5176\u5b9e\u548cheader\u539f\u7406\u5927\u81f4\u76f8\u540c\uff0c\u4e5f\u662fingress\u81ea\u52a8cookie\u503c\uff0c\u5ba2\u6237\u8bbf\u95ee\u5982\u679ccookie\u5339\u914d\uff0c\u6d41\u91cf\u5c31\u4f1a\u6d41\u5165\u4e0e\u4e4b\u5339\u914d\u7684\u540e\u7aef\u670d\u52a1<\/p>\n<\/blockquote>\n
\n
- \u66f4\u65b0v2\u7248\u672c\u7684\u7f16\u6392\u6587\u4ef6<\/li>\n<\/ul>\n
apiVersion: extensions\/v1beta1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n nginx.ingress.kubernetes.io\/canary: "true"\n nginx.ingress.kubernetes.io\/canary-weight: "50"\n nginx.ingress.kubernetes.io\/canary-by-header: "v2"\n nginx.ingress.kubernetes.io\/canary-by-header-value: "true"\n nginx.ingress.kubernetes.io\/canary-by-cookie: "user_from_shanghai"\n labels:\n app: echoserverv2\n name: echoserverv2\n namespace: echoserver\nspec:\n rules:\n - host: echo.chulinx.com\n http:\n paths:\n - backend:\n serviceName: echoserverv2\n servicePort: 8080\n path: \/\n---\nkind: Service\napiVersion: v1\nmetadata:\n name: echoserverv2\n namespace: echoserver\nspec:\n selector:\n name: echoserverv2\n type: ClusterIP\n ports:\n - name: echoserverv2\n port: 8080\n targetPort: 8080\n---\napiVersion: extensions\/v1beta1\nkind: Deployment\nmetadata:\n name: echoserverv2\n namespace: echoserver\n labels:\n name: echoserverv2\nspec:\n template:\n metadata:\n labels:\n name: echoserverv2\n spec:\n containers:\n - image: mirrorgooglecontainers\/echoserver:1.10\n name: echoserverv2 \n ports:\n - containerPort: 8080\n name: echoserverv2<\/code><\/pre>\n
\n
- \u8bbf\u95ee\u6d4b\u8bd5<\/li>\n<\/ul>\n
\n\u53ef\u4ee5\u770b\u548cheader\u7684\u8bbf\u95ee\u6548\u679c\u662f\u4e00\u6837\u7684\uff0c\u53ea\u4e0d\u8fc7cookie\u4e0d\u80fd\u81ea\u5b9a\u4e49value<\/p>\n<\/blockquote>\n
$ [K8sSj] kubectl apply -f appv2.yml\ningress.extensions\/echoserverv2 configured\nservice\/echoserverv2 unchanged\ndeployment.extensions\/echoserverv2 unchanged\n\n$ [K8sSj] for i in `seq 10`;do curl -s --cookie "user_from_shanghai" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\n\n# zlx @ zlxdeMacBook-Pro in ~\/Desktop\/unicom\/k8syml\/nginx-ingress-canary-deployment [16:01:52]\n$ [K8sSj] for i in `seq 10`;do curl -s --cookie "user_from_shanghai:always" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv1-657b966cb5-7grqs\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\n\n# zlx @ zlxdeMacBook-Pro in ~\/Desktop\/unicom\/k8syml\/nginx-ingress-canary-deployment [16:02:25]\n$ [K8sSj] for i in `seq 10`;do curl -s --cookie "user_from_shanghai=always" echo.chulinx.com|grep Hostname;done\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn\nHostname: echoserverv2-856bb5758-f9tqn<\/code><\/pre>\n
\u603b\u7ed3<\/h2>\n
\n\u7070\u5ea6\u53d1\u5e03\u53ef\u4ee5\u4fdd\u8bc1\u6574\u4f53\u7cfb\u7edf\u7684\u7a33\u5b9a\uff0c\u5728\u521d\u59cb\u7070\u5ea6\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u5bf9\u65b0\u7248\u672c\u8fdb\u884c\u6d4b\u8bd5\u3001\u53d1\u73b0\u548c\u8c03\u6574\u95ee\u9898\uff0c\u4ee5\u4fdd\u8bc1\u5176\u5f71\u54cd\u5ea6,\u4ee5\u4e0a\u5185\u5bb9\u901a\u8fc7\u5b9e\u4f8b\u8be6\u7ec6\u4ecb\u7ecd\u4e86Ingress-Nginx\u7684\u5b9e\u6218Canary Annotation\uff0c\u53ef\u4ee5\u501f\u52a9Ingress-Nginx\u8f7b\u677e\u5b9e\u73b0\u84dd\u7eff\u53d1\u5e03\u548c\u91d1\u4e1d\u96c0\u53d1\u5e03<\/p>\n<\/blockquote>\n
\u5176\u4ed6<\/h3>\n
\u5173\u4e8e\u84dd\u7eff\u53d1\u5e03\u3001\u91d1\u4e1d\u96c0\u53d1\u5e03\u3001\u548cA\/B\u6d4b\u8bd5<\/h4>\n
\n
- \u84dd\u7eff\u53d1\u5e03<\/li>\n<\/ul>\n
\n\u84dd\u7eff\u90e8\u7f72\u4e2d\uff0c\u4e00\u5171\u6709\u4e24\u5957\u7cfb\u7edf\uff1a\u4e00\u5957\u662f\u6b63\u5728\u63d0\u4f9b\u670d\u52a1\u7cfb\u7edf\uff0c\u6807\u8bb0\u4e3a\u201c\u7eff\u8272\u201d\uff1b\u53e6\u4e00\u5957\u662f\u51c6\u5907\u53d1\u5e03\u7684\u7cfb\u7edf\uff0c\u6807\u8bb0\u4e3a\u201c\u84dd\u8272\u201d\u3002\u4e24\u5957\u7cfb\u7edf\u90fd\u662f\u529f\u80fd\u5b8c\u5584\u7684\uff0c\u5e76\u4e14\u6b63\u5728\u8fd0\u884c\u7684\u7cfb\u7edf\uff0c\u53ea\u662f\u7cfb\u7edf\u7248\u672c\u548c\u5bf9\u5916\u670d\u52a1\u60c5\u51b5\u4e0d\u540c\u3002 \u6700\u521d\uff0c\u6ca1\u6709\u4efb\u4f55\u7cfb\u7edf\uff0c\u6ca1\u6709\u84dd\u7eff\u4e4b\u5206\u3002 \u7136\u540e\uff0c\u7b2c\u4e00\u5957\u7cfb\u7edf\u5f00\u53d1\u5b8c\u6210\uff0c\u76f4\u63a5\u4e0a\u7ebf\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53ea\u6709\u4e00\u4e2a\u7cfb\u7edf\uff0c\u4e5f\u6ca1\u6709\u84dd\u7eff\u4e4b\u5206\u3002 \u540e\u6765\uff0c\u5f00\u53d1\u4e86\u65b0\u7248\u672c\uff0c\u8981\u7528\u65b0\u7248\u672c\u66ff\u6362\u7ebf\u4e0a\u7684\u65e7\u7248\u672c\uff0c\u5728\u7ebf\u4e0a\u7684\u7cfb\u7edf\u4e4b\u5916\uff0c\u642d\u5efa\u4e86\u4e00\u4e2a\u4f7f\u7528\u65b0\u7248\u672c\u4ee3\u7801\u7684\u5168\u65b0\u7cfb\u7edf\u3002 \u8fd9\u65f6\u5019\uff0c\u4e00\u5171\u6709\u4e24\u5957\u7cfb\u7edf\u5728\u8fd0\u884c\uff0c\u6b63\u5728\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u8001\u7cfb\u7edf\u662f\u7eff\u8272\u7cfb\u7edf\uff0c\u65b0\u90e8\u7f72\u7684\u7cfb\u7edf\u662f\u84dd\u8272\u7cfb\u7edf\u3002 \u84dd\u8272\u7cfb\u7edf\u4e0d\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u7528\u6765\u505a\u5565\uff1f \u7528\u6765\u505a\u53d1\u5e03\u524d\u6d4b\u8bd5\uff0c\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u4efb\u4f55\u95ee\u9898\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u84dd\u8272\u7cfb\u7edf\u4e0a\u4fee\u6539\uff0c\u4e0d\u5e72\u6270\u7528\u6237\u6b63\u5728\u4f7f\u7528\u7684\u7cfb\u7edf\u3002\uff08\u6ce8\u610f\uff0c\u4e24\u5957\u7cfb\u7edf\u6ca1\u6709\u8026\u5408\u7684\u65f6\u5019\u624d\u80fd\u767e\u5206\u767e\u4fdd\u8bc1\u4e0d\u5e72\u6270\uff09 \u84dd\u8272\u7cfb\u7edf\u7ecf\u8fc7\u53cd\u590d\u7684\u6d4b\u8bd5\u3001\u4fee\u6539\u3001\u9a8c\u8bc1\uff0c\u786e\u5b9a\u8fbe\u5230\u4e0a\u7ebf\u6807\u51c6\u4e4b\u540e\uff0c\u76f4\u63a5\u5c06\u7528\u6237\u5207\u6362\u5230\u84dd\u8272\u7cfb\u7edf\uff1a \u5207\u6362\u540e\u7684\u4e00\u6bb5\u65f6\u95f4\u5185\uff0c\u4f9d\u65e7\u662f\u84dd\u7eff\u4e24\u5957\u7cfb\u7edf\u5e76\u5b58\uff0c\u4f46\u662f\u7528\u6237\u8bbf\u95ee\u7684\u5df2\u7ecf\u662f\u84dd\u8272\u7cfb\u7edf\u3002\u8fd9\u6bb5\u65f6\u95f4\u5185\u89c2\u5bdf\u84dd\u8272\u7cfb\u7edf\uff08\u65b0\u7cfb\u7edf\uff09\u5de5\u4f5c\u72b6\u6001\uff0c\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u76f4\u63a5\u5207\u6362\u56de\u7eff\u8272\u7cfb\u7edf\u3002 \u5f53\u786e\u4fe1\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u84dd\u8272\u7cfb\u7edf\u5de5\u4f5c\u6b63\u5e38\uff0c\u4e0d\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u7eff\u8272\u7cfb\u7edf\u5df2\u7ecf\u4e0d\u518d\u9700\u8981\u7684\u65f6\u5019\uff0c\u84dd\u8272\u7cfb\u7edf\u6b63\u5f0f\u6210\u4e3a\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7cfb\u7edf\uff0c\u6210\u4e3a\u65b0\u7684\u7eff\u8272\u7cfb\u7edf\u3002 \u539f\u5148\u7684\u7eff\u8272\u7cfb\u7edf\u53ef\u4ee5\u9500\u6bc1\uff0c\u5c06\u8d44\u6e90\u91ca\u653e\u51fa\u6765\uff0c\u7528\u4e8e\u90e8\u7f72\u4e0b\u4e00\u4e2a\u84dd\u8272\u7cfb\u7edf\u3002 \u84dd\u7eff\u90e8\u7f72\u53ea\u662f\u4e0a\u7ebf\u7b56\u7565\u4e2d\u7684\u4e00\u79cd\uff0c\u5b83\u4e0d\u662f\u53ef\u4ee5\u5e94\u5bf9\u6240\u6709\u60c5\u51b5\u7684\u4e07\u80fd\u65b9\u6848\u3002 \u84dd\u7eff\u90e8\u7f72\u80fd\u591f\u7b80\u5355\u5feb\u6377\u5b9e\u65bd\u7684\u524d\u63d0\u5047\u8bbe\u662f\u76ee\u6807\u7cfb\u7edf\u662f\u975e\u5e38\u5185\u805a\u7684\uff0c\u5982\u679c\u76ee\u6807\u7cfb\u7edf\u76f8\u5f53\u590d\u6742\uff0c\u90a3\u4e48\u5982\u4f55\u5207\u6362\u3001\u4e24\u5957\u7cfb\u7edf\u7684\u6570\u636e\u662f\u5426\u9700\u8981\u4ee5\u53ca\u5982\u4f55\u540c\u6b65\u7b49\uff0c\u90fd\u9700\u8981\u4ed4\u7ec6\u8003\u8651\u3002<\/p>\n<\/blockquote>\n
\n
- \u91d1\u4e1d\u96c0\u53d1\u5e03<\/li>\n<\/ul>\n
\n\u91d1\u4e1d\u96c0\u53d1\u5e03\uff08Canary\uff09\u4e5f\u662f\u4e00\u79cd\u53d1\u5e03\u7b56\u7565\uff0c\u548c\u56fd\u5185\u5e38\u8bf4\u7684\u7070\u5ea6\u53d1\u5e03\u662f\u540c\u4e00\u7c7b\u7b56\u7565\u3002\u84dd\u7eff\u90e8\u7f72\u662f\u51c6\u5907\u4e24\u5957\u7cfb\u7edf\uff0c\u5728\u4e24\u5957\u7cfb\u7edf\u4e4b\u95f4\u8fdb\u884c\u5207\u6362\uff0c\u91d1\u4e1d\u96c0\u7b56\u7565\u662f\u53ea\u6709\u4e00\u5957\u7cfb\u7edf\uff0c\u9010\u6e10\u66ff\u6362\u8fd9\u5957\u7cfb\u7edf \u8b6c\u5982\u8bf4\uff0c\u76ee\u6807\u7cfb\u7edf\u662f\u4e00\u7ec4\u65e0\u72b6\u6001\u7684Web\u670d\u52a1\u5668\uff0c\u4f46\u662f\u6570\u91cf\u975e\u5e38\u591a\uff0c\u5047\u8bbe\u6709\u4e00\u4e07\u53f0\u3002 \u8fd9\u65f6\u5019\uff0c\u84dd\u7eff\u90e8\u7f72\u5c31\u4e0d\u80fd\u7528\u4e86\uff0c\u56e0\u4e3a\u4f60\u4e0d\u53ef\u80fd\u7533\u8bf7\u4e00\u4e07\u53f0\u670d\u52a1\u5668\u4e13\u95e8\u7528\u6765\u90e8\u7f72\u84dd\u8272\u7cfb\u7edf\uff08\u5728\u84dd\u7eff\u90e8\u7f72\u7684\u5b9a\u4e49\u4e2d\uff0c\u84dd\u8272\u7684\u7cfb\u7edf\u8981\u80fd\u591f\u627f\u63a5\u6240\u6709\u8bbf\u95ee\uff09\u3002 \u53ef\u4ee5\u60f3\u5230\u7684\u4e00\u4e2a\u65b9\u6cd5\u662f\uff1a \u53ea\u51c6\u5907\u51e0\u53f0\u670d\u52a1\u5668\uff0c\u5728\u4e0a\u9762\u90e8\u7f72\u65b0\u7248\u672c\u7684\u7cfb\u7edf\u5e76\u6d4b\u8bd5\u9a8c\u8bc1\u3002\u6d4b\u8bd5\u901a\u8fc7\u4e4b\u540e\uff0c\u62c5\u5fc3\u51fa\u73b0\u610f\u5916\uff0c\u8fd8\u4e0d\u6562\u7acb\u5373\u66f4\u65b0\u6240\u6709\u7684\u670d\u52a1\u5668\u3002 \u5148\u5c06\u7ebf\u4e0a\u7684\u4e00\u4e07\u53f0\u670d\u52a1\u5668\u4e2d\u768410\u53f0\u66f4\u65b0\u4e3a\u6700\u65b0\u7684\u7cfb\u7edf\uff0c\u7136\u540e\u89c2\u5bdf\u9a8c\u8bc1\u3002\u786e\u8ba4\u6ca1\u6709\u5f02\u5e38\u4e4b\u540e\uff0c\u518d\u5c06\u5269\u4f59\u7684\u6240\u6709\u670d\u52a1\u5668\u66f4\u65b0\u3002 \u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u91d1\u4e1d\u96c0\u53d1\u5e03\u3002 \u5b9e\u9645\u64cd\u4f5c\u4e2d\u8fd8\u53ef\u4ee5\u505a\u66f4\u591a\u63a7\u5236\uff0c\u8b6c\u5982\u8bf4\uff0c\u7ed9\u6700\u521d\u66f4\u65b0\u768410\u53f0\u670d\u52a1\u5668\u8bbe\u7f6e\u8f83\u4f4e\u7684\u6743\u91cd\u3001\u63a7\u5236\u53d1\u9001\u7ed9\u8fd910\u53f0\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u6570\uff0c\u7136\u540e\u9010\u6e10\u63d0\u9ad8\u6743\u91cd\u3001\u589e\u52a0\u8bf7\u6c42\u6570\u3002 \u8fd9\u4e2a\u63a7\u5236\u53eb\u505a\u201c\u6d41\u91cf\u5207\u5206\u201d\uff0c\u65e2\u53ef\u4ee5\u7528\u4e8e\u91d1\u4e1d\u96c0\u53d1\u5e03\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u540e\u9762\u7684A\/B\u6d4b\u8bd5\u3002 \u84dd\u7eff\u90e8\u7f72\u548c\u91d1\u4e1d\u96c0\u53d1\u5e03\u662f\u4e24\u79cd\u53d1\u5e03\u7b56\u7565\uff0c\u90fd\u4e0d\u662f\u4e07\u80fd\u7684\u3002\u6709\u65f6\u5019\u4e24\u8005\u90fd\u53ef\u4ee5\u4f7f\u7528\uff0c\u6709\u65f6\u5019\u53ea\u80fd\u7528\u5176\u4e2d\u4e00\u79cd\u3002<\/p>\n<\/blockquote>\n
\n
- A\/B\u6d4b\u8bd5<\/li>\n<\/ul>\n
\n\u9996\u5148\u9700\u8981\u660e\u786e\u7684\u662f\uff0cA\/B\u6d4b\u8bd5\u548c\u84dd\u7eff\u90e8\u7f72\u4ee5\u53ca\u91d1\u4e1d\u96c0\uff0c\u5b8c\u5168\u662f\u4e24\u56de\u4e8b\u3002 \u84dd\u7eff\u90e8\u7f72\u548c\u91d1\u4e1d\u96c0\u662f\u53d1\u5e03\u7b56\u7565\uff0c\u76ee\u6807\u662f\u786e\u4fdd\u65b0\u4e0a\u7ebf\u7684\u7cfb\u7edf\u7a33\u5b9a\uff0c\u5173\u6ce8\u7684\u662f\u65b0\u7cfb\u7edf\u7684BUG\u3001\u9690\u60a3\u3002 A\/B\u6d4b\u8bd5\u662f\u6548\u679c\u6d4b\u8bd5\uff0c\u540c\u4e00\u65f6\u95f4\u6709\u591a\u4e2a\u7248\u672c\u7684\u670d\u52a1\u5bf9\u5916\u670d\u52a1\uff0c\u8fd9\u4e9b\u670d\u52a1\u90fd\u662f\u7ecf\u8fc7\u8db3\u591f\u6d4b\u8bd5\uff0c\u8fbe\u5230\u4e86\u4e0a\u7ebf\u6807\u51c6\u7684\u670d\u52a1\uff0c\u6709\u5dee\u5f02\u4f46\u662f\u6ca1\u6709\u65b0\u65e7\u4e4b\u5206\uff08\u5b83\u4eec\u4e0a\u7ebf\u65f6\u53ef\u80fd\u91c7\u7528\u4e86\u84dd\u7eff\u90e8\u7f72\u7684\u65b9\u5f0f\uff09\u3002 A\/B\u6d4b\u8bd5\u5173\u6ce8\u7684\u662f\u4e0d\u540c\u7248\u672c\u7684\u670d\u52a1\u7684\u5b9e\u9645\u6548\u679c\uff0c\u8b6c\u5982\u8bf4\u8f6c\u5316\u7387\u3001\u8ba2\u5355\u60c5\u51b5\u7b49\u3002 A\/B\u6d4b\u8bd5\u65f6\uff0c\u7ebf\u4e0a\u540c\u65f6\u8fd0\u884c\u591a\u4e2a\u7248\u672c\u7684\u670d\u52a1\uff0c\u8fd9\u4e9b\u670d\u52a1\u901a\u5e38\u4f1a\u6709\u4e00\u4e9b\u4f53\u9a8c\u4e0a\u7684\u5dee\u5f02\uff0c\u8b6c\u5982\u8bf4\u9875\u9762\u6837\u5f0f\u3001\u989c\u8272\u3001\u64cd\u4f5c\u6d41\u7a0b\u4e0d\u540c\u3002\u76f8\u5173\u4eba\u5458\u901a\u8fc7\u5206\u6790\u5404\u4e2a\u7248\u672c\u670d\u52a1\u7684\u5b9e\u9645\u6548\u679c\uff0c\u9009\u51fa\u6548\u679c\u6700\u597d\u7684\u7248\u672c\u3002 \u5728A\/B\u6d4b\u8bd5\u4e2d\uff0c\u9700\u8981\u80fd\u591f\u63a7\u5236\u6d41\u91cf\u7684\u5206\u914d\uff0c\u8b6c\u5982\u8bf4\uff0c\u4e3aA\u7248\u672c\u5206\u914d10%\u7684\u6d41\u91cf\uff0c\u4e3aB\u7248\u672c\u5206\u914d10%\u7684\u6d41\u91cf\uff0c\u4e3aC\u7248\u672c\u5206\u914d80%\u7684\u6d41\u91cf\u3002<\/p>\n<\/blockquote>\n