k8s-deployment-strategies

Kubernetes deployment strategies explained

Github星跟踪图

Kubernetes deployment strategies

In Kubernetes there is few different way to release an application, you have
to carefully choose the right strategy to make your infrastructure resilient.

  • recreate: terminate the old version and release the new one
  • ramped: release a new version on a rolling update fashion, one
    after the other
  • blue/green: release a new version alongside the old version
    then switch traffic
  • canary: release a new version to a subset of users, then proceed
    to a full rollout
  • a/b testing: release a new version to a subset of users in a
    precise way (HTTP headers, cookie, weight, etc.). This doesn’t come out of the
    box with Kubernetes, it imply extra work to setup a smarter
    loadbalancing system (Istio, Linkerd, Traeffik, custom nginx/haproxy, etc).
  • shadow: release a new version alongside the old version. Incoming
    traffic is mirrored to the new version and doesn't impact the
    response.

deployment strategy decision diagram

Before experimenting, checkout the following resources:

Getting started

These examples were created and tested on Minikube
running with Kubernetes v1.10.0.

$ minikube start --kubernetes-version v1.10.0 --memory 8192 --cpus 2

Visualizing using Prometheus and Grafana

The following steps describe how to setup Prometheus and Grafana to visualize
the progress and performance of a deployment.

Install Helm

To install Helm, follow the instructions provided on their
website.

$ helm init

Install Prometheus

$ helm install \
    --namespace=monitoring \
    --name=prometheus \
    --version=7.0.0 \
    stable/prometheus

Install Grafana

$ helm install \
    --namespace=monitoring \
    --name=grafana \
    --version=1.12.0 \
    --set=adminUser=admin \
    --set=adminPassword=admin \
    --set=service.type=NodePort \
    stable/grafana

Setup Grafana

Now that Prometheus and Grafana are up and running, you can access Grafana:

$ minikube service grafana

To login, username: admin, password: admin.

Then you need to connect Grafana to Prometheus, to do so, add a DataSource:

Name: prometheus
Type: Prometheus
Url: http://prometheus-server
Access: Server

Create a dashboard with a Graph. Use the following query:

sum(rate(http_requests_total{app="my-app"}[5m])) by (version)

To have a better overview of the version, add {{version}} in the legend field.

Example graph

Recreate:

Kubernetes deployment recreate

Ramped:

Kubernetes deployment ramped

Blue/Green:

Kubernetes deployment blue-green

Canary:

Kubernetes deployment canary

A/B testing:

kubernetes ab-testing deployment

Shadow:

kubernetes shadow deployment

主要指标

概览
名称与所有者ContainerSolutions/k8s-deployment-strategies
主编程语言Go
编程语言Go (语言数: 3)
平台
许可证
所有者活动
创建于2017-09-21 08:46:42
推送于2024-04-24 08:10:01
最后一次提交2024-04-24 05:10:01
发布数0
用户参与
星数3.6k
关注者数135
派生数1.1k
提交数59
已启用问题?
问题数4
打开的问题数1
拉请求数12
打开的拉请求数1
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?