Google Kubernetes Engine is production-ready environment for deploying containerized applications.

Quick start

The following document gives fast introduction how to set up kubernetes project. https://cloud.google.com/kubernetes-engine/docs/quickstart

Mac install of Cloud SDK

brew cask install google-cloud-sdk

Autocomplete in zshell

First check where google-cloud-sdk by

ls -la $(which gcloud)

You should probably see that is linked to bin/gcloud in /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/ So to .zshrc add

export GCLOUD_PATH=/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk
source $GCLOUD_PATH/*.zsh.inc

Init GKE

Then initialize it with

gcloud init

or you can set project by

gcloud config set project <project-name>

See existing project at https://console.cloud.google.com/cloud-resource-manager.

Install kubectl

In Kubernetes hello world we have explained how to install kubernetes with minikube for local experiments. You can also install the version that corresponds to the server one (see below for instructions).

kubectl config get-contexts
kubectl config use-context <context NAME>

After setting up a project and choosing a default one you have to choose the compute zone for it, for example:

gcloud config set compute/region us-east1
gcloud config set compute/zone us-east1-b

GKE is available in https://console.cloud.google.com/kubernetes

Create cluster

Then you can create a cluster

gcloud container clusters create <cluster-name> --num-nodes 3 

You may need to enable Kubernetes and increase In-use IP addresses quotas on https://console.cloud.google.com/iam-admin/quotas.

Test it

Create simple pod and service

kubectl create deployment flaskhelloworld --image=barteks/flaskhelloworld
kubectl expose deployment flaskhelloworld --type LoadBalancer --port 80

Now when you run

kubectl get svc flaskhelloworld

You should get EXTERNAL-IP to connect to pod. So you can run something like that

curl 34.73.187.87

And see Hello World

Delete kluster

gcloud container clusters delete <cluster-name>

Alternative install without brew

You can also install kubectl with

gcloud components install kubectl

You may need to change to python 2.7 by deactivating pyenv (pyenv local system).

Update PATH:

export PATH=/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/:$PATH

Check if it works:

kubectl version

Updated: 2019-12-26