Google Container Engine makes it easy to run docker containers in the cloud. Google Container Engine uses Kubernetes, an open source container scheduler, to ensure that your cluster is running exactly the way you want it to at all times.
Follow along this lab to learn how to launch multiple Kubernetes clusters, tie them together with a Federated control plane, and launch a Ingress controller with a single, globally addressable IP address.
If you don't already have a Google Account (Gmail or Google Apps), you must create one. Sign-in to Google Cloud Platform console (console.cloud.google.com) and create a new project:
Remember the project ID, a unique name across all Google Cloud projects (the name above has already been taken and will not work for you, sorry!). It will be referred to later in this codelab as
Next, you'll need to enable billing in the Developers Console in order to use Google Cloud resources like Cloud Datastore and Cloud Storage.
Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see "cleanup" section at the end of this document).
New users of Google Cloud Platform are eligible for a $300 free trial.
In this section you'll create a two Google Container Engine clusters.
Navigate to the the Google Cloud Console from another browser tab/window, to https://console.cloud.google.com. Use the login credential given to you by the lab proctor.
Search for "Google Compute Engine" in the search box. Click on "Google Compute Engine" in the results list that appears.
Now click "Enable"
Launch Cloud Shell by clicking on the terminal icon in the top toolbar.
Cloud Shell is a browser based terminal to a virtual machine that has the Google Cloud Platform tools installed on it and some additional tools (like editors and compilers) that are handy when you are developing or debugging your cloud application.
We'll be using the
gcloud command to create the clusters.
You can create a the container clusters with the
Create the first cluster as a background task:
gcloud container clusters create cluster-1 \ --zone=us-west1-a --quiet \ --scopes cloud-platform,storage-ro,logging-write,monitoring-write,service-control,service-management,https://www.googleapis.com/auth/ndev.clouddns.readwrite \ > /dev/null 2>&1 &
Then, create the second cluster at the same time:
gcloud container clusters create cluster-2 \ --zone=us-east1-b --quiet \ --scopes cloud-platform,storage-ro,logging-write,monitoring-write,service-control,service-management,https://www.googleapis.com/auth/ndev.clouddns.readwrite
These commands create two new clusters called "cluster-1" and "cluster-2" with three nodes (VMs). You can configure this command with additional flags to change the number of nodes, the default permissions, and other variables. See the documentation for more details. The clusters also have the "Cloud DNS" scope, which is required to set up Federation.
One cluster is located in the us-west region, while the other is located in the us-east region. You can create clusters in any Google Cloud region.
Launching the cluster may take a bit of time but once it is up you should see output in Cloud Shell that looks like this:
NAME ZONE MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS cluster-2 us-east1-b 1.5.2 220.127.116.11 n1-standard-1 1.5.2 3 RUNNING
In order for pods in a Kubernetes cluster to discover services in remote clusters, you need to create a DNS zone with a registered domain name.
In order to set up the Federation Control Plane, we will use the kubefed tool.
Download kubefed and move it into the path:
curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.2/kubernetes-client-linux-amd64.tar.gz && \ tar -xzvf kubernetes-client-linux-amd64.tar.gz && \ sudo cp kubernetes/client/bin/kubefed /usr/local/bin && \ sudo chmod +x /usr/local/bin/kubefed
The next step is to create a new federated context. This will act as a virtual "super cluster" that can schedule onto all the federated clusters.
To see the current contexts, run this command:
kubectl config get-contexts
You should see the two clusters that you created in the previous steps:
kubectl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE gke_codelab-93622_us-east1-b_cluster-2 gke_codelab-93622_us-east1-b_cluster-2 gke_codelab-93622_us-east1-b_cluster-2 * gke_codelab-93622_us-west1-a_cluster-1 gke_codelab-93622_us-west1-a_cluster-1 gke_codelab-93622_us-west1-a_cluster-1
Now, create the virtual context with the kubefed tool
Google Container Engine and Kubernetes provide a powerful and flexible way to run containers on Google Cloud Platform. StatefulSets let you run stateful workloads like databases on Kubernetes.