1. Answers
  2. Configure Kubernetes HorizontalRunnerAutoscaler with Pulumi

How Do I Configure a Kubernetes Actions.summerwind.dev Horizontalrunnerautoscaler With Pulumi?

Introduction

This guide provides a step-by-step approach to configuring a HorizontalRunnerAutoscaler using Pulumi, which is part of the actions.summerwind.dev API. The HorizontalRunnerAutoscaler is designed to automatically scale GitHub Actions runners within a Kubernetes cluster. This scaling is based on the number of queued and running workflow jobs, ensuring that resources are optimally allocated based on demand.

Key Points

  • We will create a HorizontalRunnerAutoscaler resource.
  • We will define the scaling behavior for GitHub Actions runners.
  • The configuration will be done using Pulumi in TypeScript.

Step-by-Step Process

  1. Define the Kubernetes Namespace: Begin by creating a namespace where the resources will be deployed. This namespace will house the runner system.

  2. Create the RunnerDeployment: Define a RunnerDeployment that specifies the number of runner instances and their configuration. This includes the GitHub repository and the runner image to use.

  3. Configure the HorizontalRunnerAutoscaler: Set up the HorizontalRunnerAutoscaler to manage the scaling of the runners. Define the minimum and maximum number of replicas, and specify the metrics that will trigger scaling actions.

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

// Define the Kubernetes namespace
const namespace = new k8s.core.v1.Namespace("actions-runner-system", {
    metadata: { name: "actions-runner-system" },
});

// Define the RunnerDeployment
const runnerDeployment = new k8s.apiextensions.CustomResource("runnerDeployment", {
    apiVersion: "actions.summerwind.dev/v1alpha1",
    kind: "RunnerDeployment",
    metadata: {
        name: "example-runner-deployment",
        namespace: namespace.metadata.name,
    },
    spec: {
        replicas: 2,
        template: {
            spec: {
                repository: "your-github-repo/your-repo",
                image: "summerwind/actions-runner:latest",
            },
        },
    },
});

// Define the HorizontalRunnerAutoscaler
const horizontalRunnerAutoscaler = new k8s.apiextensions.CustomResource("horizontalRunnerAutoscaler", {
    apiVersion: "actions.summerwind.dev/v1alpha1",
    kind: "HorizontalRunnerAutoscaler",
    metadata: {
        name: "example-autoscaler",
        namespace: namespace.metadata.name,
    },
    spec: {
        scaleTargetRef: {
            name: runnerDeployment.metadata.name,
        },
        minReplicas: 1,
        maxReplicas: 10,
        metrics: [
            {
                type: "TotalNumberOfQueuedAndInProgressWorkflowRuns",
                repositoryNames: ["your-github-repo/your-repo"],
                scaleUpThreshold: 5,
                scaleDownThreshold: 2,
            },
        ],
    },
});

Summary

In this guide, we successfully configured a HorizontalRunnerAutoscaler for managing GitHub Actions runners in a Kubernetes environment using Pulumi. By establishing a RunnerDeployment and setting up the autoscaler, we ensured that the number of runner instances dynamically adjusts in response to the workload. This configuration helps maintain efficiency and resource optimization within the cluster.

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