Skip to content

Files

Failed to load latest commit information.

Latest commit

 Cannot retrieve latest commit at this time.

History

History
 
 

example-gke-k8s-helm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Kubernetes Engine and Helm Example

button

Change to the example directory

[[ `basename $PWD` != example-gke-k8s-helm ]] && cd example-gke-k8s-helm

Install Terraform

  1. Install Terraform if it is not already installed (visit terraform.io for other distributions):
../terraform-install.sh

Install Helm

  1. Install the latest version of Helm:
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh

helm init --client-only
  1. Install the Terraform Helm provider:
(
  set -x; cd "$(mktemp -d)" &&
  curl -fsSLO "https://github.com/mcuadros/terraform-provider-helm/releases/download/v0.5.1/terraform-provider-helm_v0.5.1_$(uname | tr '[:upper:]' '[:lower:]')_amd64.tar.gz" &&
  tar -xvf terraform-provider-helm*.tar.gz &&
  mkdir -p ~/.terraform.d/plugins/ &&
  mv terraform-provider-helm*/terraform-provider-helm ~/.terraform.d/plugins/
)

Set up the environment

  1. Set the project, replace YOUR_PROJECT with your project ID:
PROJECT=YOUR_PROJECT
gcloud config set project ${PROJECT}
  1. Configure the environment for Terraform:
[[ $CLOUD_SHELL ]] || gcloud auth application-default login
export GOOGLE_PROJECT=$(gcloud config get-value project)
  1. Create the terraform.tfvars file:
cat > terraform.tfvars <<EOF
helm_version = "$(helm version -c --short | egrep -o 'v[0-9]*.[0-9]*.[0-9]*')"
acme_email = "$(gcloud config get-value account)"
EOF

cat terraform.tfvars

Enable service management API

This example creates a Cloud Endpoints service and requires that the Service Manangement API is enabled.

  1. Enable the Service Management API:
gcloud services enable servicemanagement.googleapis.com

Run Terraform

  1. If you have run this example before within the last 30 days, undelete the Cloud Endpoints service named drupal:
gcloud endpoints services undelete drupal.endpoints.$(gcloud config get-value project).cloud.goog
  1. Run Terraform:
terraform init
terraform apply

Testing

  1. Wait for the load balancer to be provisioned:
./test.sh
  1. After the Drupal pods start and are ready, open the interface by navigating to the URL:
echo $(terraform output endpoint)
  1. Login with the credentials displayed in the following commands:
echo User: $(terraform output drupal_user)
echo Password: $(terraform output drupal_password)

Connecting with kubectl and helm

  1. Get the cluster credentials and configure kubectl:
gcloud container clusters get-credentials $(terraform output cluster_name) --zone $(terraform output cluster_zone)
  1. Verify kubectl connectivity:
kubectl get pods

helm list

Cleanup

  1. Delete the nginx-ingress helm release first so that the forwarding rule and firewall rule are cleaned up by the GCE controller:
terraform destroy -input=false -auto-approve -target helm_release.nginx-ingress && sleep 60 && \
terraform destroy