Skip to content

A simple example that deploys a GKE cluster and an application to the cluster using pulumi

License

Notifications You must be signed in to change notification settings

snigdhasambitak/go-gke-pulumi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy

Google Kubernetes Engine (GKE) Cluster

This example deploys a Google Cloud Platform (GCP) Google Kubernetes Engine (GKE) cluster and an application to it

Deploying the App

To deploy your infrastructure, follow the below steps.

Prerequisites

  1. Install Pulumi

  2. Install Go 1.13 or later

  3. Install Google Cloud SDK (gcloud)

  4. Configure GCP Auth

    • Login using gcloud

      $ 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.

Steps

After cloning this repo, from this working directory, run these commands:

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

    This will initialize the Pulumi program in Golang.

    $ pulumi stack init
  2. Set the required GCP configuration variables:

    This sets configuration options and default values for our cluster.

    $ pulumi config set gcp:project <YOUR_GCP_PROJECT_HERE>
    $ pulumi config set gcp:zone us-west1-a     // any valid GCP Zone here
  3. Stand up the GKE cluster:

    To preview and deploy changes, run pulumi update and select "yes."

    The update sub-command shows a preview of the resources that will be created and prompts on whether to proceed with the deployment. Note that the stack itself is counted as a resource, though it does not correspond to a physical cloud resource.

    You can also run pulumi up --diff to see and inspect the diffs of the overall changes expected to take place.

    Running pulumi up will deploy the GKE cluster. Note, provisioning a new GKE cluster takes between 3-5 minutes.

    $ pulumi update
    Previewing update (dev):
    
        Type                      Name            Plan
    +   pulumi:pulumi:Stack       gcp-go-gke-dev  create
    +   └─ gcp:container:Cluster  helloworld      create
    
    Resources:
        + 2 to create
    
    Updating (dev):
    
        Type                      Name            Plan
    +   pulumi:pulumi:Stack       gcp-go-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.

  5. Access the Kubernetes Cluster using kubectl

    To access your new Kubernetes cluster using kubectl, we need to setup the kubeconfig file and download kubectl. We can leverage the Pulumi stack output in the CLI, as Pulumi facilitates exporting these objects for us.

    $ pulumi stack output kubeconfig --show-secrets > kubeconfig
    $ export KUBECONFIG=$PWD/kubeconfig
    
    $ kubectl version
    $ kubectl cluster-info
    $ kubectl get nodes
  6. Once you've finished experimenting, tear down your stack's resources by destroying and removing it:

    $ pulumi destroy --yes
    $ pulumi stack rm --yes

About

A simple example that deploys a GKE cluster and an application to the cluster using pulumi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages