Ephemeral Cloud: Revolutionize Infrastructure with Crossplane & kube-green

Ephemeral Cloud: Revolutionize Infrastructure with Crossplane, kube-green

Building Ephemeral Cloud Infrastructure with Crossplane and kube-green: A Guide to Sustainable, Cost-Effective Kubernetes

The modern cloud native landscape demands efficiency, but many organizations still rely on static, always-on infrastructure that drives up costs and environmental impact. This article explores how to build ephemeral cloud infrastructure using the powerful combination of Crossplane and kube-green. By shifting to an on-demand model, platform teams can automate resource management, drastically cut waste, and align their cloud operations with both fiscal and sustainability goals.

The Paradigm Shift: Why Ephemeral Cloud Infrastructure Matters

For years, the standard approach to cloud infrastructure involved provisioning resources-virtual machines, databases, Kubernetes clusters-and leaving them running 24/7. This model, while simple, is inherently wasteful. Development, testing, and staging environments often sit idle outside of business hours, consuming expensive compute, memory, and energy resources without delivering any value. According to a DZone article on the topic, this practice is a significant source of unnecessary cloud expenditure and carbon emissions.

The move toward ephemeral cloud infrastructure represents a fundamental shift from “always-on” to “on-demand.” In this new paradigm, resources are provisioned dynamically when needed and are automatically suspended or destroyed when they are not. This approach not only optimizes costs but also fosters a more disciplined and sustainable operational culture. The goal is to treat infrastructure as a transient, programmable asset rather than a static, long-lived liability. This is where tools built on the Kubernetes ecosystem, like Crossplane and kube-green, become indispensable.

Crossplane: The Universal Control Plane for Your Cloud

At the heart of modern, automated infrastructure provisioning is the need for a unified control plane. Crossplane, an open-source Kubernetes add-on, steps into this role by extending the Kubernetes API to manage and compose infrastructure from multiple cloud providers and services.

“Crossplane is a Universal Control Plane that offers a standardized API and operational model to manage almost any resource. This makes Crossplane ideal for organizations creating internal clouds.” – Upbound Blog

How Crossplane Works: Leveraging Kubernetes CRDs

Crossplane achieves its “universal” capabilities by using Kubernetes Custom Resource Definitions (CRDs). As detailed in an Upbound blog post, CRDs allow developers to create new, custom Kubernetes objects. Crossplane provides a vast library of CRDs that represent cloud resources like AWS S3 buckets, Google Cloud SQL databases, or Azure Kubernetes Service (AKS) clusters. This enables several key benefits:

  • Declarative, API-Driven Management: Teams can define their entire infrastructure stack in YAML files, just like they manage their applications. The Kubernetes control plane then works to reconcile the desired state with the actual state in the cloud provider.
  • Self-Service for Developers: Platform teams can create simplified, abstract infrastructure APIs (called Compositions) for developers. This allows a developer to request a “PostgreSQL-database” without needing to know the complex underlying cloud provider configurations, effectively creating a self-service Platform-as-a-Service (PaaS).
  • Portability and Composability: By abstracting away provider-specific details, Crossplane makes it easier to build applications that are portable across different cloud environments.

With Crossplane, provisioning the components of an ephemeral environment-a database, a message queue, a Kubernetes namespace-becomes a simple, repeatable, and API-driven task, setting the stage for automated lifecycle management.

kube-green: Automating Sustainability in Kubernetes

While Crossplane excels at provisioning infrastructure, kube-green excels at making it sustainable. Developed by Davide Bianchi, a Senior Technical Leader at Mia-Platform, this open-source Kubernetes operator was created specifically to tackle the problem of idle resource consumption.

“To help reduce the cloud native carbon footprint, I developed kube-green, an open source Kubernetes controller on GitHub.” — Davide Bianchi, Senior Technical Leader, Mia-Platform, PlatformCon 2023

The kube-green operator automates the process of shutting down and waking up Kubernetes workloads like Deployments, StatefulSets, and CronJobs based on a predefined schedule. Instead of running scripts or relying on manual intervention, teams can apply a simple `SleepInfo` Custom Resource to a namespace, and kube-green handles the rest. During “sleep” hours, it scales down deployments to zero replicas, effectively halting their CPU, memory, and energy consumption. When the “wake-up” time arrives, it restores the deployments to their original replica count, making the environment ready for use.

The Synergy: Combining Crossplane and kube-green for Maximum Impact

The true power of an ephemeral cloud infrastructure strategy is realized when Crossplane and kube-green are used together. They address two different-but complementary-parts of the infrastructure lifecycle: dynamic provisioning and automated suspension. This combination enables a fully automated, on-demand workflow that is both efficient and sustainable.

“Use Crossplane and kube-green to replace wasteful, always-on cloud environments with on-demand, ephemeral ones, dramatically cutting costs and environmental impact.” – DZone

A Typical Ephemeral Environment Workflow

  1. On-Demand Provisioning (Crossplane): A developer needs a new environment for testing a feature. They commit a simple YAML file to a Git repository, defining their request using a custom API created by the platform team with Crossplane. This API might provision a dedicated Kubernetes namespace, a PostgreSQL database, and a Redis cache.
  2. Automated Reconciliation: Crossplane’s controllers detect the new resource claim and automatically provision the required infrastructure in the appropriate cloud provider (AWS, GCP, etc.).
  3. Intelligent Suspension (kube-green): The namespace provisioned by Crossplane is automatically labeled or configured to be managed by kube-green. At the end of the workday (e.g., 7 PM), the kube-green operator scales all deployments within that namespace down to zero.
  4. Scheduled Wake-Up: The next morning (e.g., 8 AM), kube-green automatically scales the deployments back up, ensuring the environment is ready for the developer without any manual action.
  5. De-provisioning: Once the feature is merged and the environment is no longer needed, the developer deletes the YAML file from the Git repository, and Crossplane automatically tears down all associated cloud resources, preventing resource leaks.

This closed-loop system ensures that resources exist only when they are actively needed, directly translating to significant savings and a smaller carbon footprint.

Quantifying the Gains: Real-World Cost and Environmental Savings

The adoption of this ephemeral model is not just a theoretical improvement; it delivers measurable results that impact both the balance sheet and corporate sustainability reports.

Tangible Cost Reductions

Organizations that have integrated the kube-green operator into their workflows have reported remarkable financial benefits. According to a Red Hat blog post, adopters have seen their monthly cloud costs drop by 30-40%. These savings come from reducing the compute hours billed for non-production environments during nights and weekends. Furthermore, this automation frees up valuable developer and operator time that would otherwise be spent manually managing these idle clusters.

Measurable Environmental Impact

Beyond cost, the environmental benefits are equally compelling. A case study documented by Collabnix on a single Kubernetes cluster demonstrated a dramatic reduction in resource consumption after implementing kube-green:

  • Pods: The number of running pods decreased from 446 to 205 during sleep hours.
  • Memory Usage: Consumption dropped from 28 GB to 16 GB, saving 12 GB of memory.
  • CPU Usage: CPU utilization fell from 2 cores to 1.3 cores.

These resource reductions translated directly into a lower carbon footprint, with an estimated CO₂e (carbon dioxide equivalent) savings of 28 kg per week, or 1,456 kg per year, for just one cluster. When scaled across an entire organization, the cumulative environmental benefit becomes substantial.

Operational Efficiency and Monitoring

To ensure transparency, kube-green exposes Prometheus metrics out-of-the-box. This allows platform teams to build dashboards that visualize the sleep state of various namespaces, quantify resource savings over time, and track the positive environmental impact of their ephemeral infrastructure strategy. This data-driven approach helps justify the investment and encourages wider adoption within the organization.

Practical Implementation: Getting Started with Ephemeral Infrastructure

Adopting this model involves integrating Crossplane and kube-green into your existing Kubernetes environment. While a full implementation guide is extensive, here are the high-level steps to get started.

Step 1: Setting Up the Crossplane Control Plane

First, install Crossplane into your Kubernetes cluster. You will then need to install and configure the specific `Providers` for the cloud services you intend to manage (e.g., `provider-aws`, `provider-gcp`). This involves creating a Kubernetes `Secret` with your cloud provider credentials. For detailed instructions, refer to the official Crossplane documentation.

Step 2: Defining Composite Resources for Self-Service

Create a `CompositeResourceDefinition` (XRD) to define the abstract, user-facing API for your developers. Then, write a `Composition` to map that abstract API to a concrete set of cloud resources. For example, an XRD for a `WebAppEnvironment` could be composed of an RDS instance, an S3 bucket, and a Kubernetes namespace.

Step 3: Deploying the kube-green Operator

Install the kube-green operator in your cluster, typically via a Helm chart or by applying its manifests directly. You can find the installation guide on the kube-green GitHub repository. Once installed, the operator will start watching for `SleepInfo` resources.

Step 4: Configuring SleepSchedules with `SleepInfo` CRDs

To schedule a namespace to sleep, you create a `SleepInfo` resource. This simple YAML object tells kube-green which namespaces to manage and when to put them to sleep and wake them up. Here is a practical example that puts all deployments in the `dev-team-a` namespace to sleep on weekdays from 8 PM to 8 AM.


apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: dev-namespace-sleep
  namespace: dev-team-a # The namespace to put to sleep
spec:
  weekdays: "1-5" # Monday to Friday
  sleepAt: "20:00" # 8 PM
  wakeUpAt: "08:00" # 8 AM
  timeZone: "Europe/Rome"
  suspendDeployments: true # Explicitly enable for Deployments
  suspendCronJobs: true # Also suspend any CronJobs

By applying this manifest, you have effectively automated the resource management for that development environment.

Use Cases in Action: From Development to Research

The ephemeral infrastructure pattern powered by Crossplane and kube-green is applicable across numerous scenarios:

  • Development and Test Environments: This is the most common use case. Teams can spin up isolated, fully-featured environments per feature branch and have them automatically suspended when not in use, drastically reducing the cost of non-production workloads.
  • CI/CD and Pull Request Previews: For every pull request, a CI/CD pipeline can use Crossplane to provision a complete preview environment. After the PR is merged or closed, Crossplane tears it all down automatically.
  • Educational and Research Labs: Universities and research institutions can provide students and researchers with on-demand access to complex lab environments. These labs can be automatically suspended or deleted after a class or experiment concludes, optimizing the use of limited grant funding and institutional resources.

Conclusion

The combination of Crossplane and kube-green provides a robust, Kubernetes-native solution for building truly ephemeral cloud infrastructure. By automating the provisioning, suspension, and de-provisioning of resources, organizations can move beyond wasteful, always-on models. This shift delivers significant cost savings, reduces environmental impact, and enhances operational efficiency, proving that technical excellence and corporate responsibility can go hand-in-hand. For more technical deep-dives on implementation, consider exploring solution blogs on sites like OpsMind Tech.

Ready to make your cloud operations more efficient and sustainable? Explore the documentation for Crossplane and kube-green today, and start your journey toward on-demand infrastructure. Share this article to help others build a greener, more cost-effective cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *