本文首发于:Jenkins 中文社区git
这是渐进式交付系列的第二篇文章,第一篇请看:Kubernetes 中的渐进式交付:蓝绿部署和金丝雀部署。github
我使用的个人 Croc Hunter 示例项目评估了 Jenkins X 中金丝雀部署和蓝绿色部署的三种渐进式交付方案。docker
这里能够查看 Shipper、Isito 和 Flager 的示例代码。api
因为 Shipper 对建立的 Helm 图表有多个限制,所以我必须对应用作一些更改。 并且 Jenkins X 只从 master 分支构建 Helm 包,因此咱们不能作 PRs 的滚动部署,只能对 master 分支作滚动部署。app
应用标签不能包含发布名称,例如: app: {{ template “fullname” . }}
不起做用, 须要一些相似这样的标签: app: {{ .Values.appLabel }}
。less
由 Jenkins X 生成的图表致使应用滚动失败,归因于生成的 templates/release.yaml
可能和 jenkins.io/releases CRD
冲突。url
Chart croc-hunter-jenkinsx-0.0.58 failed to render: could not decode manifest: no kind "Release" is registered for version "jenkins.io/v1"
咱们只须要将 jx step changelog
更改成 jx step changelog -generate-yaml =false
,这样就不会生成文件。spa
在多集群环境,须要在 shipper 应用 yaml 中为 chartmuseum 和 docker registry 使用公开的 url,以便其余集群能够发现管理集群服务来下载图表。code
咱们能够建立这个虚拟服务, 将全部进入 Ingress 网关的主机为 croc-hunter.istio.example.org
的请求的 1% 的流量发送到 Jenkins X 预览环境( PR 号为 35 )。server
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: croc-hunter-jenkinsx namespace: jx-production spec: gateways: - public-gateway.istio-system.svc.cluster.local - mesh hosts: - croc-hunter.istio.example.com http: - route: - destination: host: croc-hunter-jenkinsx.jx-production.svc.cluster.local port: number: 80 weight: 99 - destination: host: croc-hunter-jenkinsx.jx-carlossg-croc-hunter-jenkinsx-serverless-pr-35.svc.cluster.local port: number: 80
咱们能够为 Jenkins X 在 jx-production 命名空间中部署的图表建立一个 Canary 对象, 全部新的 Jenkins X 对 jx-production 的 promotions 每次将自动滚动 10% , 若是出现任何失败,将自动回滚。
apiVersion: flagger.app/v1alpha2 kind: Canary metadata: # canary name must match deployment name name: jx-production-croc-hunter-jenkinsx namespace: jx-production spec: # deployment reference targetRef: apiVersion: apps/v1 kind: Deployment name: jx-production-croc-hunter-jenkinsx # HPA reference (optional) # autoscalerRef: # apiVersion: autoscaling/v2beta1 # kind: HorizontalPodAutoscaler # name: jx-production-croc-hunter-jenkinsx # the maximum time in seconds for the canary deployment # to make progress before it is rollback (default 600s) progressDeadlineSeconds: 60 service: # container port port: 8080 # Istio gateways (optional) gateways: - public-gateway.istio-system.svc.cluster.local # Istio virtual service host names (optional) hosts: - croc-hunter.istio.example.com canaryAnalysis: # schedule interval (default 60s) interval: 15s # max number of failed metric checks before rollback threshold: 5 # max traffic percentage routed to canary # percentage (0-100) maxWeight: 50 # canary increment step # percentage (0-100) stepWeight: 10 metrics: - name: istio_requests_total # minimum req success rate (non 5xx responses) # percentage (0-100) threshold: 99 interval: 1m - name: istio_request_duration_seconds_bucket # maximum req duration P99 # milliseconds threshold: 500 interval: 30s
译者:王冬辉