1. Pulumi Templates
  2. Kubernetes Cluster Templates
  3. Kubernetes Cluster on Google Cloud

Kubernetes Cluster on Google Cloud

The Kubernetes Cluster template creates an infrastructure as code project in your favorite language and deploys a managed Kubernetes cluster to Google Cloud with Pulumi. The architecture includes a VPC network with a subnet and deploys a Google Kubernetes Engine (GKE) cluster that provides a managed Kubernetes control plane and a nodepool for the cluster. Kubernetes worker nodes are deployed with private IP addresses for improved security. The template gives you a working project out of the box that you can customize easily and extend to suit your needs.

An architecture diagram of the Pulumi Google Cloud Kubernetestemplate

Using this template

To use this template to deploy your own Kubernetes cluster, make sure you’ve installed Pulumi and configured your Google Cloud credentials, then create a new project using the template in your language of choice:

$ mkdir my-k8s-cluster && cd my-k8s-cluster
$ pulumi new kubernetes-gcp-typescript
Alternatively, you can create and configure a new project with this template (kubernetes-gcp-typescript) in the Pulumi Service.
$ mkdir my-k8s-cluster && cd my-k8s-cluster
$ pulumi new kubernetes-gcp-python
Alternatively, you can create and configure a new project with this template (kubernetes-gcp-python) in the Pulumi Service.
$ mkdir my-k8s-cluster && cd my-k8s-cluster
$ pulumi new kubernetes-gcp-go
Alternatively, you can create and configure a new project with this template (kubernetes-gcp-go) in the Pulumi Service.
$ mkdir my-k8s-cluster && cd my-k8s-cluster
$ pulumi new kubernetes-gcp-csharp
Alternatively, you can create and configure a new project with this template (kubernetes-gcp-csharp) in the Pulumi Service.
$ mkdir my-k8s-cluster && cd my-k8s-cluster
$ pulumi new kubernetes-gcp-yaml
Alternatively, you can create and configure a new project with this template (kubernetes-gcp-yaml) in the Pulumi Service.

Follow the prompts to complete the new-project wizard. When it’s done, you’ll have a complete Pulumi project that’s ready to deploy and configured with the most common settings. Feel free to inspect the code in index.js index.ts __main__.py main.go Program.cs Program.fs Program.vb App.java Pulumi.yaml for a closer look.

Deploying the project

You must supply an existing project ID to deploy the cluster. You can input the project ID through the new-project wizard. No additional configuration is required.

Once the new project is created, you can deploy it immediately with pulumi up:

$ pulumi up

When the deployment completes, Pulumi exports the following stack output values:

networkName
The name of the virtual network containing the Kubernetes cluster resources.
networkId
The unique ID of the virtual network containing the Kubernetes cluster resources.
clusterName
The name of the GKE cluster.
clusterId
The unique ID of the GKE cluster
kubeconfig
The cluster’s kubeconfig file which you can use with kubectl to access and communicate with your clusters.

Output values like these are useful in many ways, most commonly as inputs for other stacks or related cloud resources.

Customizing the project

Projects created with the Kubernetes Cluster template expose the following configuration settings:

gcp:project
The Google Cloud project ID to deploy into.
gcp:region
The Google Cloud region to deploy into. Defaults to us-central1.
nodesPerZone
The desired number of nodes per zone in the nodepool. Defaults to 1.

All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing their values with pulumi config set as shown below:

$ pulumi config set someProp ../some/value
$ pulumi up

Tidying up

You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:

$ pulumi destroy

Learn more

Congratulations! You’re now well on your way to managing a production-grade Kubernetes cluster on Google Cloud with Pulumi — and there’s lots more you can do from here: