debian-mirror-gitlab/doc/user/project/canary_deployments.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
7.9 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2021-03-11 19:13:27 +05:30
# Canary Deployments **(FREE)**
2019-07-31 22:56:46 +05:30
2022-05-07 20:08:51 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/1659) in GitLab 9.1.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212320) from GitLab Premium to GitLab Free in 13.8.
2019-07-31 22:56:46 +05:30
2019-12-04 20:38:33 +05:30
A popular [Continuous Deployment](https://en.wikipedia.org/wiki/Continuous_deployment)
2019-07-31 22:56:46 +05:30
strategy, where a small portion of the fleet is updated to the new version of
your application.
## Overview
2020-04-22 19:07:51 +05:30
When embracing [Continuous Delivery](https://about.gitlab.com/blog/2016/08/05/continuous-integration-delivery-and-deployment-with-gitlab/), a company needs to decide what
2019-07-31 22:56:46 +05:30
type of deployment strategy to use. One of the most popular strategies is canary
deployments, where a small portion of the fleet is updated to the new version
first. This subset, the canaries, then serve as the proverbial
[canary in the coal mine](https://en.wiktionary.org/wiki/canary_in_a_coal_mine).
If there is a problem with the new version of the application, only a small
percentage of users are affected and the change can either be fixed or quickly
reverted.
2020-04-22 19:07:51 +05:30
Leveraging [Kubernetes' Canary deployments](https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#canary-deployments), visualize your canary
2021-11-11 11:23:49 +05:30
deployments right inside the [deploy board](deploy_boards.md), without the need to leave GitLab.
2019-07-31 22:56:46 +05:30
## Use cases
Canary deployments can be used when you want to ship features to only a portion of
your pods fleet and watch their behavior as a percentage of your user base
visits the temporarily deployed feature. If all works well, you can deploy the
2021-02-22 17:27:13 +05:30
feature to production knowing that it shouldn't cause any problems.
2019-07-31 22:56:46 +05:30
2022-05-07 20:08:51 +05:30
Canary deployments are also especially required for backend refactors, performance
2019-07-31 22:56:46 +05:30
improvements, or other changes where the user interface doesn't change, but you
want to make sure the performance stays the same, or improves. Developers need
to be careful when using canaries with user-facing changes, because by default,
2021-02-22 17:27:13 +05:30
requests from the same user are randomly distributed between canary and
2019-07-31 22:56:46 +05:30
non-canary pods, which could result in confusion or even errors. If needed, you
may want to consider [setting `service.spec.sessionAffinity` to `ClientIP` in
2020-04-22 19:07:51 +05:30
your Kubernetes service definitions](https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies), but that is beyond the scope of
2019-07-31 22:56:46 +05:30
this document.
## Enabling Canary Deployments
2021-11-11 11:23:49 +05:30
Canary deployments require that you properly configure deploy boards:
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
1. Follow the steps to [enable deploy boards](deploy_boards.md#enabling-deploy-boards).
2022-05-07 20:08:51 +05:30
1. To track canary deployments you must label your Kubernetes deployments and
2020-04-22 19:07:51 +05:30
pods with `track: canary`. To get started quickly, you can use the [Auto Deploy](../../topics/autodevops/stages.md#auto-deploy)
2019-07-31 22:56:46 +05:30
template for canary deployments that GitLab provides.
Depending on the deploy, the label should be either `stable` or `canary`.
2020-11-24 15:15:51 +05:30
GitLab assumes the track label is `stable` if the label is blank or missing.
Any other track label is considered `canary` (temporary).
This allows GitLab to discover whether a deployment is stable or canary (temporary).
2019-07-31 22:56:46 +05:30
Once all of the above are set up and the pipeline has run at least once,
2022-05-07 20:08:51 +05:30
Go to the environments page under **Pipelines > Environments**.
2021-11-11 11:23:49 +05:30
As the pipeline executes, deploy boards clearly mark canary pods, enabling
2022-05-07 20:08:51 +05:30
quick and clear insight into the status of each environment and deployment.
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
Canary deployments are marked with a yellow dot in the deploy board so that you
2022-05-07 20:08:51 +05:30
can quickly notice them.
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
![Canary deployments on deploy board](img/deploy_boards_canary_deployments.png)
2021-01-29 00:20:46 +05:30
2021-12-11 22:18:48 +05:30
### Advanced traffic control with Canary Ingress (DEPRECATED)
2021-01-29 00:20:46 +05:30
2022-05-07 20:08:51 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/215501) in GitLab 13.6.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/212320) from GitLab Premium to GitLab Free in 13.8.
2021-12-11 22:18:48 +05:30
> - [Deprecated](https://gitlab.com/groups/gitlab-org/configure/-/epics/8) in GitLab 14.5.
WARNING:
This feature was [deprecated](https://gitlab.com/groups/gitlab-org/configure/-/epics/8) in GitLab 14.5.
2021-01-29 00:20:46 +05:30
Canary deployments can be more strategic with [Canary Ingress](https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#canary),
which is an advanced traffic routing service that controls incoming HTTP
requests between stable and canary deployments based on factors such as weight, sessions, cookies,
and others. GitLab uses this service in its [Auto Deploy architecture](../../topics/autodevops/upgrading_auto_deploy_dependencies.md#v2-chart-resource-architecture)
2022-05-07 20:08:51 +05:30
to let users quickly and safely roll out their new deployments.
2021-01-29 00:20:46 +05:30
#### How to set up a Canary Ingress in a canary deployment
A Canary Ingress is installed by default if your Auto DevOps pipeline uses
[`v2.0.0+` of `auto-deploy-image`](../../topics/autodevops/upgrading_auto_deploy_dependencies.md#verify-dependency-versions).
A Canary Ingress becomes available when you create a new canary deployment and is destroyed when the
canary deployment is promoted to production.
Here's an example setup flow from scratch:
1. Prepare an [Auto DevOps-enabled](../../topics/autodevops/index.md) project.
2021-11-18 22:05:49 +05:30
1. Set up a [Kubernetes Cluster](../../user/infrastructure/clusters/index.md) in your project.
2021-09-04 01:27:46 +05:30
1. Install [NGINX Ingress](https://github.com/kubernetes/ingress-nginx/tree/master/charts/ingress-nginx) in your cluster.
2021-09-30 23:02:18 +05:30
1. Set up [the base domain](../../user/project/clusters/gitlab_managed_clusters.md#base-domain) based on the Ingress
2021-01-29 00:20:46 +05:30
Endpoint assigned above.
1. Check if [`v2.0.0+` of `auto-deploy-image` is used in your Auto DevOps pipelines](../../topics/autodevops/upgrading_auto_deploy_dependencies.md#verify-dependency-versions).
If it isn't, follow the documentation to specify the image version.
1. [Run a new Auto DevOps pipeline](../../ci/pipelines/index.md#run-a-pipeline-manually)
and make sure that the `production` job succeeds and creates a production environment.
1. Configure a [`canary` deployment job for Auto DevOps pipelines](../../topics/autodevops/customize.md#deploy-policy-for-canary-environments).
1. [Run a new Auto DevOps pipeline](../../ci/pipelines/index.md#run-a-pipeline-manually)
and make sure that the `canary` job succeeds and creates a canary deployment with Canary Ingress.
#### How to check the current traffic weight on a Canary Ingress
2021-11-11 11:23:49 +05:30
1. Visit the [deploy board](../../user/project/deploy_boards.md).
2021-02-22 17:27:13 +05:30
1. View the current weights on the right.
2021-01-29 00:20:46 +05:30
2021-02-22 17:27:13 +05:30
![Rollout Status Canary Ingress](img/canary_weight.png)
2021-01-29 00:20:46 +05:30
#### How to change the traffic weight on a Canary Ingress
2022-05-07 20:08:51 +05:30
You can change the traffic weight in your environment's deploy board by using [GraphiQL](../../api/graphql/getting_started.md#graphiql),
2021-01-29 00:20:46 +05:30
or by sending requests to the [GraphQL API](../../api/graphql/getting_started.md#command-line).
2021-11-11 11:23:49 +05:30
To use your [deploy board](../../user/project/deploy_boards.md):
2021-02-22 17:27:13 +05:30
2022-05-07 20:08:51 +05:30
1. Go to **Deployments > Environments** for your project.
1. Set the new weight with the dropdown list on the right side.
2021-02-22 17:27:13 +05:30
1. Confirm your selection.
2021-01-29 00:20:46 +05:30
Here's an example using [GraphiQL](../../api/graphql/getting_started.md#graphiql):
1. Visit [GraphiQL Explorer](https://gitlab.com/-/graphql-explorer).
1. Execute the `environmentsCanaryIngressUpdate` GraphQL mutation:
```shell
mutation {
environmentsCanaryIngressUpdate(input:{
id: "gid://gitlab/Environment/29", # Your Environment ID. You can get the ID from the URL of the environment page.
weight: 45 # The new traffic weight. e.g. If you set `45`, 45% of traffic goes to a canary deployment and 55% of traffic goes to a stable deployment.
}) {
errors
}
}
```
1. If the request succeeds, the `errors` response contains an empty array. GitLab sends a `PATCH`
request to your Kubernetes cluster for updating the weight parameter on a Canary Ingress.