Skip to content

Shut down inference containers when stream is down #432

@dthaler

Description

@dthaler

Here’s a simplified example that scales down the inference-system Deployment in the point-robinson namespace:

using System;
using System.Threading.Tasks;
using k8s;
using k8s.Models;

class Program
{
    static async Task Main(string[] args)
    {
        // Load kubeconfig (default: ~/.kube/config)
        var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
        IKubernetes client = new Kubernetes(config);

        string namespaceName = "point-robinson";
        string deploymentName = "inference-system";

        // Get the Deployment
        var deployment = await client.ReadNamespacedDeploymentAsync(deploymentName, namespaceName);

        // Set replicas to 0
        deployment.Spec.Replicas = 0;

        // Update the Deployment
        await client.ReplaceNamespacedDeploymentAsync(deployment, deploymentName, namespaceName);

        Console.WriteLine($"Scaled down {deploymentName} in {namespaceName} to 0 replicas.");
    }
}
  • This only affects the Deployment in that namespace — other namespaces remain untouched.
  • Once replicas = 0, the ReplicaSet won’t recreate pods, so CPU usage drops to zero for that workload.
  • You can later set deployment.Spec.Replicas = 1 (or more) to bring it back.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions