DEV Community

Imran Hayder
Imran Hayder

Posted on

Canary deployment in Gitlab using nginx-ingress

Canary deployments in gitlab AutoDevops using nginx-ingress

Gitlab AutoDevops is a great feature in Gitlab which allows us to Build,Test,Deploy our apps seamlessly to Kubernetes.

This tutorial will not walk over steps to configure kubernetes integration in Gitlab as its already well documented here.

AutoDevops Helm Chart setup for canary-deployments

This chart is the modified form of official auto-deploy-app that is intended to achieve traffic routing in canary deployment using nginx-ingress.

Assuming you have already configured your Gitlab project with AutoDevops, next is to use the modified chart that I created here ->
AutoDevops is completely customizable, so in order to use this chart instead of official chart, all you need to do is copy the files and move under chart directory in your repo.

Next, you want to enable canary stage which can be done simply in your .gitlab-ci.yml as:

  - template: Auto-DevOps.gitlab-ci.yml

Traffic Routing in Auto Deploy canary deployments using Nginx-ingress

The traffic routing in canary deployment is done based on header value while using nginx-ingress and AutoDevOps.

How it works

We used canary by header value feature of nginx-ingress annotations

For that we had to modify official chart to add two additional resources that are created during canary stage:

  • canary-ingress
  • canary-service

Alt Text

The canary-ingress checks for header canary, if set, routes to canary service backend that then forwards to canary-deployment.

There was a bug auto-deploy-app where the production service was pointing to both production deployment and production-canary deployment based on its selectors, which is raised here

Testing in AutoDevops

Simply set CANARY_ENABLED in your .gitlab-ci.yml when using AutoDevops.
Deploy the app using this chart in
productionand then tocanary`.

Now make a request to service URL as:

curl -H "canary: always" http://<service-url>

This will hit the canary-ingress that will route to canary-deployment that you can verfiy in pod logs.

Top comments (0)