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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set gcp-cs-gkecd pulumi-examples/gcp-cs-gkeThis example deploys a Google Cloud Platform (GCP) Google Kubernetes Engine (GKE) cluster using C#.
Prerequisites#
-
Configure GCP auth by logging in using
gcloud:Terminal window gcloud auth logingcloud config set project <YOUR_GCP_PROJECT_HERE>gcloud auth application-default loginNote: 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#
-
Create a new Pulumi stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init dev -
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 -
Stand up the GKE cluster by running
pulumi upand selecting “yes.” Note that provisioning a new GKE cluster takes between 3-5 minutes. You can also runpulumi up --diffto see and inspect the diffs of the overall changes expected to take place.Terminal window pulumi upUpdating (dev):Type Name Plan+ pulumi:pulumi:Stack gcp-cs-gke-dev created+ └─ gcp:container:Cluster helloworld createdOutputs:ClusterName: "helloworld-9b9530f"KubeConfig : "<KUBECONFIG_CONTENTS>"Resources:+ 2 createdDuration: 3m3s -
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 thekubeconfigfile and usekubectl:Terminal window pulumi stack output kubeconfig --show-secrets > kubeconfigexport KUBECONFIG=$PWD/kubeconfigkubectl versionkubectl cluster-infokubectl get nodes
Cleaning up#
Once you are done, you can destroy all of the resources, and the stack:
pulumi destroypulumi stack rm