Consider these key questions to determine if ephemeral environments would benefit your workflow:
Do you need isolated testing environments?
Ephemeral environments provide isolated testing spaces for each feature or branch, preventing conflicts between developers and ensuring clean test conditions for every change.
Are your environments complex to set up?
When environments require multiple services, databases, and configurations, ephemeral environments automate this complex process, ensuring consistent setups every time and saving hours of manual configuration.
Do you have high infrastructure costs?
By automatically creating environments when needed and destroying them when work is complete, ephemeral environments can significantly reduce cloud infrastructure costs compared to maintaining multiple permanent environments.
Do you need to test branch-specific changes?
Ephemeral environments create isolated testing spaces that exactly match your branch configuration, making it easy to validate changes in context before merging to the main codebase.
Is your team growing?
As teams scale, coordinating environment usage becomes increasingly challenging. Ephemeral environments eliminate contention by giving each developer or team their own dedicated space to work without interference.
If you answered yes to any of these questions, implementing ephemeral environments with Ctrlplane could significantly improve your development workflow and reduce operational overhead.
Once the pull request resource is created, we now determine what pipelines need
to be take give the state of the Pull Request. In our scenario we will create a
GKE cluster for each PR.
.github/workflows/deploy-gke-cluster.yml
Copy
name: Deploy GKE Clusterrun-name: Deploy GKE Cluster [${{ inputs.job_id }}]on: workflow_dispatch: inputs: job_id: description: "Job ID" required: truejobs: create-gke: runs-on: ubuntu-latest steps: - name: Authenticate to Google Cloud uses: google-github-actions/auth@v1 with: credentials_json: ${{ secrets.GCP_SA_KEY }} - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v1 - id: ctrlplane uses: ctrlplanedev/ctrlplane/github/get-job-inputs@main with: job_id: ${{ inputs.job_id }} api_key: ${{ secrets.CTRLPLANE_API_KEY }} # the pull request number, this was set in the config body # when creating the pull request resource: # `--config "pullRequest=${{ github.event.pull_request.number }}"` required_outputs: | resource_config_pullRequest - name: Install Ctrlplane CLI uses: ctrlplanedev/cli@main with: workspace: ${{ secrets.CTRLPLANE_WORKSPACE_ID }} api_key: ${{ secrets.CTRLPLANE_API_KEY }} - name: Create GKE Cluster run: | # Create a unique cluster name based on PR CLUSTER_NAME="pr-${{ outputs.ctrlplane.resource_config_pullRequest }}" REGION="us-central1" # Create GKE cluster gcloud container clusters create $CLUSTER_NAME \ --region $REGION \ --num-nodes 1 \ --machine-type e2-standard-2 # Get cluster credentials gcloud container clusters get-credentials $CLUSTER_NAME --region $REGION # Create Ctrlplane resource for the cluster ctrlc api upsert resource \ --version "gke/v1" \ --kind "Cluster" \ --identifier "gke/$CLUSTER_NAME" \ --name "$CLUSTER_NAME" \ --config "project=${{ secrets.GCP_PROJECT_ID }}" \ --config "region=$REGION" \ --config "cluster=$CLUSTER_NAME" \ --metadata "pr=${{ github.event.pull_request.number }}" \ --metadata "branch=${{ github.event.pull_request.head.ref }}" \ --link "GCP Console=https://console.cloud.google.com/kubernetes/clusters/details/$REGION/$CLUSTER_NAME"
If you wanted to speed up the creation of the cluster, you could instead
deploy to a namespace in an existing cluster.