1. Answers
  2. How Do I Configure A Kubernetes Argoproj.io Rollout With Pulumi?

How Do I Configure a Kubernetes Argoproj.io Rollout With Pulumi?

Configuring a Kubernetes Argo Rollout with Pulumi

In this guide, we will walk through the steps to configure a Kubernetes Argo Rollout using Pulumi. Argo Rollouts is a Kubernetes controller and set of CRDs (Custom Resource Definitions) which provide advanced deployment capabilities such as blue-green and canary deployments.

Step-by-Step Explanation

Step 1: Install Pulumi and Dependencies

First, ensure that you have Pulumi installed on your machine. You can follow the installation guide on the Pulumi website. Additionally, you will need Node.js and npm installed.

Step 2: Create a New Pulumi Project

Create a new Pulumi project by running the following commands:

mkdir pulumi-argo-rollout
cd pulumi-argo-rollout
pulumi new typescript

This will create a new Pulumi project with a TypeScript template.

Step 3: Install Pulumi Kubernetes Provider

Install the Pulumi Kubernetes provider by running:

npm install @pulumi/kubernetes

Step 4: Define the Argo Rollout Resource

In your index.ts file, import the necessary modules and define the Argo Rollout resource. Below is an example configuration for a canary deployment:

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

const appLabels = { app: "nginx" };

const rollout = new k8s.apiextensions.CustomResource("nginx-rollout", {
    apiVersion: "argoproj.io/v1alpha1",
    kind: "Rollout",
    metadata: {
        name: "nginx-rollout",
    },
    spec: {
        replicas: 3,
        selector: {
            matchLabels: appLabels,
        },
        template: {
            metadata: {
                labels: appLabels,
            },
            spec: {
                containers: [{
                    name: "nginx",
                    image: "nginx:1.19.2",
                    ports: [{ containerPort: 80 }],
                }],
            },
        },
        strategy: {
            canary: {
                steps: [
                    { setWeight: 20 },
                    { pause: { duration: "5m" } },
                    { setWeight: 40 },
                    { pause: { duration: "5m" } },
                    { setWeight: 60 },
                    { pause: { duration: "5m" } },
                    { setWeight: 80 },
                    { pause: { duration: "5m" } },
                    { setWeight: 100 },
                ],
            },
        },
    },
});

Step 5: Deploy the Rollout

Run the following command to deploy the Argo Rollout to your Kubernetes cluster:

pulumi up

This will provision the Argo Rollout resource in your Kubernetes cluster.

Summary

In this guide, we have walked through the steps to configure a Kubernetes Argo Rollout using Pulumi. We installed the necessary dependencies, created a new Pulumi project, defined the Argo Rollout resource, and deployed it to the Kubernetes cluster. Argo Rollouts provide advanced deployment strategies such as canary and blue-green deployments, making it easier to manage application updates in a Kubernetes environment.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

const appLabels = { app: "nginx" };

const rollout = new k8s.apiextensions.CustomResource("nginx-rollout", {
    apiVersion: "argoproj.io/v1alpha1",
    kind: "Rollout",
    metadata: {
        name: "nginx-rollout",
    },
    spec: {
        replicas: 3,
        selector: {
            matchLabels: appLabels,
        },
        template: {
            metadata: {
                labels: appLabels,
            },
            spec: {
                containers: [{
                    name: "nginx",
                    image: "nginx:1.19.2",
                    ports: [{ containerPort: 80 }],
                }],
            },
        },
        strategy: {
            canary: {
                steps: [
                    { setWeight: 20 },
                    { pause: { duration: "5m" } },
                    { setWeight: 40 },
                    { pause: { duration: "5m" } },
                    { setWeight: 60 },
                    { pause: { duration: "5m" } },
                    { setWeight: 80 },
                    { pause: { duration: "5m" } },
                    { setWeight: 100 },
                ],
            },
        },
    },
});

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up