Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Google Kubernetes Engine (GKE) cluster

A GCP C# Pulumi program with Kubernetes

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set gcp-cs-gke
cd pulumi-examples/gcp-cs-gke

This example deploys a Google Cloud Platform (GCP) Google Kubernetes Engine (GKE) cluster using C#.

Prerequisites#

  1. Install Pulumi

  2. Configure GCP credentials

  3. Install .NET

  4. Install Google Cloud SDK (gcloud)

  5. Configure GCP auth by logging in using gcloud:

    Terminal window
    gcloud auth login
    gcloud config set project <YOUR_GCP_PROJECT_HERE>
    gcloud auth application-default login

    Note: This auth mechanism is meant for inner loop developer workflows. If you want to run this example in an unattended service account setting, such as in CI/CD, please follow instructions to configure your service account. The service account must have the role Kubernetes Engine Admin / container.admin.

Deploying the example#

  1. Create a new Pulumi stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init dev
  2. Set the required GCP configuration variables:

    Terminal window
    pulumi config set gcp:project <YOUR_GCP_PROJECT_HERE>
    pulumi config set gcp:zone us-west1-a
  3. Stand up the GKE cluster by running pulumi up and selecting “yes.” Note that provisioning a new GKE cluster takes between 3-5 minutes. You can also run pulumi up --diff to see and inspect the diffs of the overall changes expected to take place.

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Plan
    + pulumi:pulumi:Stack gcp-cs-gke-dev created
    + └─ gcp:container:Cluster helloworld created
    Outputs:
    ClusterName: "helloworld-9b9530f"
    KubeConfig : "<KUBECONFIG_CONTENTS>"
    Resources:
    + 2 created
    Duration: 3m3s
  4. After 3-5 minutes, your cluster will be ready, and the kubeconfig JSON you’ll use to connect to the cluster will be available as an output. To access your new Kubernetes cluster using kubectl, set up the kubeconfig file and use kubectl:

    Terminal window
    pulumi stack output kubeconfig --show-secrets > kubeconfig
    export KUBECONFIG=$PWD/kubeconfig
    kubectl version
    kubectl cluster-info
    kubectl get nodes

Cleaning up#

Once you are done, you can destroy all of the resources, and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.