Kubernetesã§Blue-Green Deploymentãã¦ã¿ã
ä»åã¯ãµã¼ãã¹ãæ¬çªã§éç¨ãã¦ããã¨ãã«æ¬²ãããªãBlue-Green DeploymentãKubernetesã§ãã£ã¦ã¿ã¾ãã
TL;DR
- Serviceã®selectorãæ´æ°ããããæ¹ã ã¨10åç¨åº¦Blueã¨Greenãã¾ãã
- Istioã使ç¨ããã°ç¬æã«100%ã®ãã©ãã£ãã¯ãåãåããããã®ã§Blue-Green Deploymentãã§ãã
ç°å¢
- GKE 1.9.7-gke.0
2種é¡ã®API
Blueã¨Greenãè¦åããããã«ãèªèº«ã®è²ãè¿ãAPIãç¨æãã¾ãã
package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "blue-api") } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":80", nil) }
ããã¦ããã®APIã稼åããDeploymentãããã§ãã
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: blue-api spec: replicas: 1 template: metadata: labels: app: color-api version: blue spec: containers: - name: blue-api image: asia.gcr.io/hoge/color-api:blue ports: - containerPort: 80 --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: green-api spec: replicas: 1 template: metadata: labels: app: color-api version: green spec: containers: - name: green-api image: asia.gcr.io/hoge/color-api:green ports: - containerPort: 80
Serviceã§B/Gãã¦ã¿ã
Kubernetesã¯Serviceã§ã¢ã¯ã»ã¹ããPodãè¦ã¤ãã¦ããã®ã§ãããã®è¨å®ãæ¸ãæããã°B/Gã§ãããã§ãã
apiVersion: v1 kind: Service metadata: name: service-color-api spec: selector: app: color-api version: green # version: blue type: NodePort ports: - protocol: TCP port: 80 targetPort: 80 name: http
versionãblueã¨greenã§å¤ãã¦ã¿ãçµæããã®ããã«ãªãã¾ããã
ã¡ãã£ã¨ãããã¥ããã§ããã
ç¹ç·ã®æéã§åãæ¿ããè¡ããBlueï¼ä¸ï¼ããGreenï¼ä¸ï¼ã«ãã©ãã£ãã¯ãåãæ¿ããããã«Serviceãæ¸ãæãã¾ããã
Serviceã®è¨å®ãæ´æ°ããããã¹ã¦ã®ãã©ãã£ãã¯ãGreenã«è¡ã£ã¦ã»ããã¨ããã§ããã10åã»ã©ä¸¡æ¹ã®Podã«ã¢ã¯ã»ã¹ãè¡ã£ã¦ãã¾ã£ã¦ãã¾ãã
ããã§ã¯APIã®ãã¼ã¸ã§ãã³ã°ãã§ãã¦ããªãã¨ä¸æ´åãããã¦ãã¾ãæ£ããåããªãæããããã¾ãã
ãªã«ãè¨å®ãæ¼ãã¦ããã®ããããã¾ããã
åå ãç¥ã£ã¦ããã°æãã¦ã»ããã§ã...
ä½è«ã§ãããåãæ¿ããç´å¾ã«åã®è²ã®Podãåé¤ãããã¨ã§ãç¬æã«å ¨ã¦ã®ãã©ãã£ãã¯ãæ°ããè²ã«æµããã¨ãã§ãã¾ãã
ç¬æã«100%ã®ãã©ãã£ãã¯ãåãæ¿ãããã®ã§å¥ã®ã¢ããã¼ãã¨ãã¦ãµã¼ãã¹ã¡ãã·ã¥ã®Istioãå°å ¥ãã¦ã¿ã¾ãã
Istioã§B/Gãã
ã¾ãã¯Istioã®å°å
¥ããã¾ãã
å
¬å¼ããã¥ã¡ã³ãã®ã¹ãããï¼ã¾ã§ã§Istioã®å°å
¥ã¯å®äºã§ãã
Istioã§çµè·¯ã®å¶å¾¡ãããã®ã§ãServiceã¯Blueã«ãGreenã«ãéä¿¡ãã§ããããã«ãã¦ããã¾ãã
apiVersion: v1 kind: Service metadata: name: service-color-api labels: app: color-api spec: selector: app: color-api type: NodePort ports: - protocol: TCP port: 80 targetPort: 80 name: http
Istioã使ç¨ããå ´åã¯Istioç¨ã®Ingressãéããªãã¨çµè·¯å¶å¾¡ãªã©ãã§ããªãã®ã§ãå°ãè¨å®ã«å¤æ´ãå ¥ãã¾ãã
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: color-ingress annotations: kubernetes.io/ingress.class: "istio" spec: backend: serviceName: service-color-api servicePort: 80
æå¾ã«æ¬å½ã®çµè·¯å¶å¾¡ã®è¨å®ãããã¾ãã
apiVersion: config.istio.io/v1alpha2 kind: RouteRule metadata: name: color-api spec: destination: name: service-color-api precedence: 1 route: - labels: version: green
ä»åãselectorãæ¸ãæãããã¨ã§å¶å¾¡ã§ãã¾ãã
å®æçãªã¢ã¯ã»ã¹ãããç¶æ
ã§åãæ¿ããã¨ãã®ããã«ãªãã¾ããã
åå¾ã§ããã¡ããªã¯ã¹ãCPUå©ç¨çãããªãã£ãã®ã§ããã¾ãããã°ã©ãã«ã¯ãªã£ã¦ãã¾ããããåãæ¿ããç´å¾ãããã¹ã¦ã®ãã©ãã£ãã¯ãæ°ããã»ãã«æµãã¦ãã¾ãã
Prometheusãå°å
¥å¾ã«ä»åº¦ã¯ã¢ã¯ã»ã¹æ°ãã°ã©ãåãã¦è¿½è¨ãããã¨ãããã¾ãã
ã¾ã¨ã
ãµã¼ãã¹ã¡ãã·ã¥ãå
¥ããã¨ãã©ãã£ãã¯ã®æ£ç¢ºãªå¶å¾¡ãã§ãã¾ãã
ããããå¶å¾¡ã®ããã®ãããã·ã追å ããã¦ãã¾ããããä½è¨ãªãªã½ã¼ã¹ã使ããã¨ã«ããªã£ã¦ãã¾ãã¾ãã
ãã¡ãªãããåå¨ãã¾ãããIstioãå
¥ãã¦ãã¾ãã°B/Gã ãã§ãªãã«ããªã¢ãªãªã¼ã¹ãã§ããããã«ãªãã®ã§ã
ãªãªã¼ã¹ãæ£ç¢ºã«è¡ãããã«Istioãå°å
¥ããã®ãããããããã¾ããã