Google Kubernetes Engine (GKE) cluster
A GCP Go 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-go-gkecd pulumi-examples/gcp-go-gkeThis example deploys a Google Cloud Platform (GCP) Google Kubernetes Engine (GKE) cluster and an application to it.
Prerequisites#
-
Configure GCP auth by logging in with
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 stack:
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 -
Install dependencies:
Terminal window go mod download -
Stand up the GKE cluster by running
pulumi up. Note that provisioning a new GKE cluster takes between 3-5 minutes:Terminal window pulumi upUpdating (dev):Type Name Plan+ pulumi:pulumi:Stack gcp-go-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.
-
Access the Kubernetes cluster using
kubectl. Set up thekubeconfigfile from the Pulumi stack output, then run your usualkubectlcommands:Terminal window pulumi stack output kubeconfig --show-secrets > kubeconfigexport KUBECONFIG=$PWD/kubeconfigkubectl versionkubectl cluster-infokubectl get nodes
Cleaning up#
Once you’re finished experimenting, tear down your stack’s resources by destroying and removing it:
pulumi destroypulumi stack rm