All guides

Canary releases with Argo Rollouts

Argo Rollouts adds a Rollout resource that its documentation describes as equivalent to a Deployment, with canary steps, traffic routing through ingress controllers and service meshes, and automated promotion or rollback based on metrics.

Over the shoulder of someone working in a code editor on a laptop

The Rollout resource

The concepts page describes a Rollout as a Kubernetes workload resource equivalent to a Deployment. It is intended to replace a Deployment when more advanced deployment or progressive delivery functionality is needed. It lists what a Rollout adds: blue-green and canary deployments, integration with ingress controllers and service meshes for traffic routing, integration with metric providers, and automated promotion or rollback based on metrics.

The pod template is the same as in a Deployment. A Rollout can also take its pod template from an existing workload such as a Deployment, through workloadRef.

Install the controller. The kubectl plugin is optional, and the last line installs it with Homebrew.

Shell

kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts \
  -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml
brew install argoproj/tap/kubectl-argo-rollouts

Canary steps

setWeight sets the percentage of traffic the canary receives. pause instructs the rollout to pause: for the time in duration, or indefinitely when none is set.

YAML

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: my-app
spec:
  replicas: 10
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: registry.example.com/my-app:1.4.2
          ports:
            - containerPort: 80
  strategy:
    canary:
      steps:
        - setWeight: 10
        - pause:
            duration: 1h
        - setWeight: 20
        - pause: {}

The steps are those of the documentation's example. The names, the image, the weights and the duration are yours to choose.

When .spec.template changes, the controller evaluates each step before the new ReplicaSet is promoted to the stable version. The first creation of a Rollout is different. It scales up to 100% at once and skips the steps and analysis, since no upgrade has occurred.

Replica counts or traffic routing

With no traffic management, the Rollout makes a best effort to reach the weight through replica counts. The documentation gives numbers: with 10 replicas and a setWeight of 10%, the controller scales the new ReplicaSet to 1 replica and the stable one to 9. For 41% it runs 4 new pods and 6 old ones. The Getting Started page calls the result an approximate canary weight, reached through normal Kubernetes Service networking.

For finer control of the percentages, the documentation points to traffic management. The Rollout then names a canary Service and a stable Service. This fragment comes from the Istio page:

YAML

strategy:
  canary:
    canaryService: canary-svc
    stableService: stable-svc
    trafficRouting:
      istio:
        virtualService:
          name: rollout-vsvc
          routes:
            - primary

The VirtualService must contain an HTTP route with two destinations whose hosts match the two Services. With traffic management, the stable ReplicaSet remains fully scaled up through the canary steps, so that it can handle 100% of the traffic at any time.

The documentation lists these traffic providers: AWS ALB Ingress Controller, Ambassador Edge Stack, Apache APISIX, Google Cloud, Gateway API through a plugin, Istio, Kong Ingress, Nginx Ingress Controller, Service Mesh Interface and Traefik Proxy.

Analysis with Prometheus

An AnalysisTemplate defines how to perform a canary analysis: the metrics, their frequency and the values considered successful or failed. This is the documentation's example:

YAML

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  args:
  - name: service-name
  metrics:
  - name: success-rate
    interval: 5m
    successCondition: result[0] >= 0.95
    failureLimit: 3
    provider:
      prometheus:
        address: http://prometheus.example.com:9090
        query: |
          sum(irate(
            istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}",response_code!~"5.*"}[5m]
          )) /
          sum(irate(
            istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}"}[5m]
          ))

The query reads Istio metrics. The documentation says you can use any metric available to your Prometheus instance, and suggests validating the PromQL expression in the Prometheus GUI first. Prometheus queries return a vector, hence result[0].

A Rollout runs the template in the background with this block from the same example:

YAML

strategy:
  canary:
    analysis:
      templates:
      - templateName: success-rate
      startingStep: 2
      args:
      - name: service-name
        value: guestbook-svc.default.svc.cluster.local

startingStep: 2 delays the analysis run until the third step. The documentation describes the outcome. If the success rate is measured below 95% three times, the analysis is considered Failed. The rollout aborts, the canary weight goes back to zero and the Rollout is considered Degraded.

Completed runs are Successful, Failed or Inconclusive, and the rollout continues, aborts or pauses accordingly. failureLimit defaults to 0, which tolerates no failures. Analysis can also be an inline analysis step, which blocks the rollout until the run completes.

The kubectl plugin commands

These are the examples from the plugin's command reference, for a Rollout named guestbook:

Shell

kubectl argo rollouts get rollout guestbook -w
kubectl argo rollouts promote guestbook
kubectl argo rollouts promote guestbook --full
kubectl argo rollouts abort guestbook
kubectl argo rollouts retry rollout guestbook
kubectl argo rollouts undo guestbook

get rollout -w shows a tree view of the Rollout and its child resources and watches its progress. promote promotes a rollout paused at a canary step, and --full skips analysis, pauses and steps. abort stops the current rollout and reverts all steps, and the previous ReplicaSet becomes active. retry rollout retries an aborted rollout. undo rolls back to the previous rollout.

Checks before you rely on it

  1. Aborted is still Degraded. After an abort, the Rollout scales up the stable version and is still considered Degraded, because the desired version is not the one running. Change the desired state back to the previous, stable version to make it Healthy.
  2. Going back is fast-tracked. Take a Rollout that was aborted or is partway through an update, and re-apply the stable manifest to it. The controller treats that as a rollback and skips analysis and the steps.
  3. Traffic outside the mesh. With Istio, only traffic within the service mesh follows the rollout strategy.
  4. The plugin version. Run kubectl argo rollouts version to check the plugin you installed.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides