1. Answers
  2. Dynamic scaling of worker nodes for cost optimization in GCP Composer

How do I dynamically scale worker nodes for cost optimization in GCP Composer?

In this guide, we will demonstrate how to dynamically scale worker nodes in Google Cloud Composer to optimize costs. We will use Pulumi, an infrastructure as code tool, to define and manage the GCP Composer environment. By configuring the workloadsConfig property of the Composer environment, we can set the minimum and maximum counts for worker nodes, allowing the environment to scale based on demand.

Below is a Pulumi program written in TypeScript that creates a GCP Composer environment with dynamic scaling for worker nodes:

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

// Define the GCP Composer environment
const composerEnvironment = new gcp.composer.Environment("my-composer-environment", {
    name: "my-composer-env",
    region: "us-central1",
    config: {
        nodeConfig: {
            machineType: "n1-standard-1",
            network: "default",
            subnetwork: "default",
        },
        softwareConfig: {
            imageVersion: "composer-1.17.7-airflow-1.10.15",
        },
        workloadsConfig: {
            worker: {
                cpu: 1,
                memoryGb: 3.75,
                minCount: 1,  // Minimum number of worker nodes
                maxCount: 5,  // Maximum number of worker nodes
            },
        },
    },
});

// Export the Composer environment's URI
export const airflowUri = composerEnvironment.config.airflowUri;

Key Points

  1. Node Configuration: The nodeConfig property specifies the machine type and network settings for the nodes in the Composer environment.
  2. Software Configuration: The softwareConfig property defines the version of Composer and Airflow to use.
  3. Workloads Configuration: The workloadsConfig property includes the worker configuration, which sets the cpu, memoryGb, minCount, and maxCount for worker nodes. This enables dynamic scaling of worker nodes based on demand.

Summary

We have created a Google Cloud Composer environment using Pulumi with dynamic scaling of worker nodes. By configuring the workloadsConfig property, we can optimize costs by allowing the number of worker nodes to scale up or down based on the workload. This ensures that resources are used efficiently, reducing unnecessary costs while maintaining performance.

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