带有 Helm 图表的蓝绿部署
Blue Green Deployment with Helm Charts
我们可以使用 'Helm Charts' 和
来部署应用程序
helm install --name the-release helm/the-service-helm --namespace myns
我们冷 'Rolling Upgrade' 部署使用,
helm upgrade --recreate-pods the-release helm/the-service-helm --namespace myns
有没有办法用'Helm Charts'实现'Blue/Green'部署?
让我们从定义开始
既然有many deployment strategies,那我们就从定义开始吧
The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them, let's say blue for the example, is live. As you prepare a new release of your software you do your final stage of testing in the green environment. Once the software is working in the green environment, you switch the router so that all incoming requests go to the green environment - the blue one is now idle.
Blue/Green
不推荐在 Helm 中使用。但是有变通方案
根据 helm issue #3518,不建议将 Helm
用于 blue/green
或 canary
部署。
至少有 3 个基于 Helm 的解决方案,见下文
不过,对于这种情况,有一个 Helm 图表。
头盔本身(TL;DR:不推荐)
Helm 本身不适用于这种情况。看他们的解释:
direct support for blue / green deployment pattern in helm · Issue #3518 · helm/helm
Helm works more in the sense of a traditional package manager, upgrading charts from one version to the next in a graceful manner (thanks to pod liveness/readiness probes and deployment update strategies), much like how one expects something like apt upgrade
to work. Blue/green deployments are a very different beast compared to the package manager style of upgrade workflows; blue/green sits at a level higher in the toolchain because the use cases around these deployments require step-in/step-out policies, gradual traffic migrations and rollbacks. Because of that, we decided that blue/green deployments are something out of scope for Helm, though a tool that utilizes Helm under the covers (or something parallel like istio) could more than likely be able to handle that use case.
基于Helm
的其他解决方案
至少有三个基于Helm
的解决方案,描述和比较here:
Shipper 来自 Booking.com
bookingcom/shipper:使用 Helm 的 Kubernetes 原生多集群金丝雀或蓝绿部署
It does this by relying on Helm, and using Helm Charts as the unit of configuration deployment. Shipper's Application object provides an interface for specifying values to a Chart just like the helm command line tool.
Shipper consumes Charts directly from a Chart repository like ChartMuseum, and installs objects into clusters itself. This has the nice property that regular Kubernetes authentication and RBAC controls can be used to manage access to Shipper APIs.
使用 Helm 的 Kubernetes 原生多集群金丝雀或蓝绿部署
Istio
你可以试试like this:
kubectl create -f <(istioctl kube-inject -f cowsay-v1.yaml) # deploy v1
kubectl create -f <(istioctl kube-inject -f cowsay-v2.yaml) # deploy v1
Flagger.
有 Flagger 团队编写的指南:Blue/Green Deployments - Flagger
本指南向您展示如何使用 Flagger 和 Kubernetes
自动执行 Blue/Green 部署
您可以尝试 Helm 本身
此外,作为 Kamol Hasan recommended, you can try that chart: puneetsaraswat/HelmCharts/blue-green。
{{ if .Values.blue.enabled }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "blue-green.fullname" . }}-blue
labels:
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "blue-green.name" . }}
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ template "blue-green.name" . }}
release: {{ .Release.Name }}
slot: blue
spec:
containers:
- name: {{ template "blue-green.name" . }}-blue
image: nginx:stable
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
# This (and the volumes section below) mount the config map as a volume.
volumeMounts:
- mountPath: /usr/share/nginx/html
name: wwwdata-volume
volumes:
- name: wwwdata-volume
configMap:
name: {{ template "blue-green.fullname" . }}
{{ end }}
我们可以使用 'Helm Charts' 和
来部署应用程序helm install --name the-release helm/the-service-helm --namespace myns
我们冷 'Rolling Upgrade' 部署使用,
helm upgrade --recreate-pods the-release helm/the-service-helm --namespace myns
有没有办法用'Helm Charts'实现'Blue/Green'部署?
让我们从定义开始
既然有many deployment strategies,那我们就从定义开始吧
The blue-green deployment approach does this by ensuring you have two production environments, as identical as possible. At any time one of them, let's say blue for the example, is live. As you prepare a new release of your software you do your final stage of testing in the green environment. Once the software is working in the green environment, you switch the router so that all incoming requests go to the green environment - the blue one is now idle.
Blue/Green
不推荐在 Helm 中使用。但是有变通方案
根据 helm issue #3518,不建议将
Helm
用于blue/green
或canary
部署。至少有 3 个基于 Helm 的解决方案,见下文
不过,对于这种情况,有一个 Helm 图表。
头盔本身(TL;DR:不推荐)
Helm 本身不适用于这种情况。看他们的解释:
direct support for blue / green deployment pattern in helm · Issue #3518 · helm/helm
Helm works more in the sense of a traditional package manager, upgrading charts from one version to the next in a graceful manner (thanks to pod liveness/readiness probes and deployment update strategies), much like how one expects something like
apt upgrade
to work. Blue/green deployments are a very different beast compared to the package manager style of upgrade workflows; blue/green sits at a level higher in the toolchain because the use cases around these deployments require step-in/step-out policies, gradual traffic migrations and rollbacks. Because of that, we decided that blue/green deployments are something out of scope for Helm, though a tool that utilizes Helm under the covers (or something parallel like istio) could more than likely be able to handle that use case.
基于Helm
的其他解决方案
至少有三个基于Helm
的解决方案,描述和比较here:
Shipper 来自 Booking.com
bookingcom/shipper:使用 Helm 的 Kubernetes 原生多集群金丝雀或蓝绿部署
It does this by relying on Helm, and using Helm Charts as the unit of configuration deployment. Shipper's Application object provides an interface for specifying values to a Chart just like the helm command line tool. Shipper consumes Charts directly from a Chart repository like ChartMuseum, and installs objects into clusters itself. This has the nice property that regular Kubernetes authentication and RBAC controls can be used to manage access to Shipper APIs.
使用 Helm 的 Kubernetes 原生多集群金丝雀或蓝绿部署
Istio
你可以试试like this:
kubectl create -f <(istioctl kube-inject -f cowsay-v1.yaml) # deploy v1
kubectl create -f <(istioctl kube-inject -f cowsay-v2.yaml) # deploy v1
Flagger.
有 Flagger 团队编写的指南:Blue/Green Deployments - Flagger 本指南向您展示如何使用 Flagger 和 Kubernetes
自动执行 Blue/Green 部署您可以尝试 Helm 本身
此外,作为 Kamol Hasan recommended, you can try that chart: puneetsaraswat/HelmCharts/blue-green。
{{ if .Values.blue.enabled }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "blue-green.fullname" . }}-blue
labels:
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: {{ template "blue-green.name" . }}
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ template "blue-green.name" . }}
release: {{ .Release.Name }}
slot: blue
spec:
containers:
- name: {{ template "blue-green.name" . }}-blue
image: nginx:stable
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
# This (and the volumes section below) mount the config map as a volume.
volumeMounts:
- mountPath: /usr/share/nginx/html
name: wwwdata-volume
volumes:
- name: wwwdata-volume
configMap:
name: {{ template "blue-green.fullname" . }}
{{ end }}