GKE

In an attempt to jump on the Kubernetes bandwagon, more and more managed Kubernetes services are being introduced. In a previous post, we explored how to deploy a Kubernetes cluster on Amazon EKS. This time, we will cover the steps for performing a similar process, this time on Google’s Kubernetes Engine.

What is Google Kubernetes Engine (GKE)?

Originally a Google-spawned project, it’s no surprise that Kubernetes is strongly intertwined and supported in the public cloud services provided by Google. In fact, Google was among the first public cloud providers to offer a fully managed Kubernetes service called the Google Kubernetes Engine, or GKE. 

Similar to the other players in this field, GKE allows users to deploy Kubernetes without the need to install, manage and operate the clusters on their own, thus eliminating a key pain-point when running Kubernetes. It provides users with full control over cluster management and container orchestration, including load-balancing, networking as well as access to all Kubernetes features.

Users can run Kubernetes in a Google Cloud Platform-friendly environment, meaning they can reap the benefits of seamless integrations with other cloud tooling provided by Google such as Code Shell, Stackdriver, and more.

Step 0: Before you start

In this tutorial, I use the GCP console to create the Kubernetes cluster and Code Shell for connecting and interacting with it. You can, of course, do the same from your CLI, but this requires you have the following set up:

Step 1: Create a new project

If you’re a newcomer to GCP, I recommend you start by creating a new project for your Kubernetes cluster — this will enable you to sandbox your resources more easily and safely.

In the console, simply click the project name in the menu bar at the top of the page, click New Project, and enter the details of the new project:

new project

Step 2: Creating your cluster

We can now start the process for deploying our Kubernetes cluster. Open the Kubernetes Engine page in the console, and click the Create cluster button (the first time you access this page, the Kubernetes API will be enabled. This might take a minute or two):

Kubernetes cluster

GKE offers a number of cluster templates you can use, but for this tutorial, we will make do with the template selected by default — a Standard cluster.

There a are a bunch of settings we need to configure:

  • Name – a name for the cluster.
  • Location type – you can decide whether to deploy the cluster to a GCP zone or region. Read up on the difference between regional and zonal resources here.
  • Node pools (optional) – node pools are a subset of node instances within a cluster that all have the same configuration. You have the option to edit the number of nodes in the default pool or add a new node pool.

There are other advanced networking and security settings that can be configured here but you can use the default settings for now and click the Create button to deploy the cluster.

After a minute or two, your Kubernetes cluster is deployed and available for use.

available

Step 3: Connecting to the cluster

Clicking the name of the cluster, we can see a lot of information about the deployment, including the Kubernetes version deployed, its endpoint, the size of the cluster and more. Conveniently, we can edit the deployment’s state.

Conveniently, GKE provides you with various management dashboards that we can use to manage the different resources of our cluster, replacing the now deprecated Kubernetes dashboard:

  • Clusters – displays cluster name, its size, total cores, total memory, node version, outstanding notifications, and more.
  • Workloads – displays the different workloads deployed on the clusters, e.g. Deployments, StatefulSets, DaemonSets and Pods.
  • Services – displays a project’s Service and Ingress resources
  • Applications – displays your project’s Secret and ConfigMap resources.
  • Configuration
  • Storage – displays PersistentVolumeClaim and StorageClass resources associated with your clusters.

To connect to the newly created cluster, you will need to configure kubectl to communicate with it. You can do this via your CLI or using GCP’s Cloud Shell. For the latter, simply click the Connect button on the right, and then the Run in Cloud Shell button. The command to connect to the cluster is already entered in Cloud Shell:

cloud shell

Hit Enter to connect. You should see this output:

To test the connection, use:

Step 4: Deploying a sample app

Our last step is to deploy a sample guestbook application on our Kubernetes cluster.

To do this, first clone the Kubernetes examples repository. Again, you can do this locally in your CLI or using GCP’s Cloud Shell:

Access the guestbook project:

The directory contains all the configuration files required to deploy the app — the Redis backend and the PHP frontend.

We’ll start by deploying our Redis master:

Then, the Redis master service:

To add high availability into the mix, we’re going to add two Redis worker replicas:

Our application needs to communicate to the Redis workers to be able to read data, so to make the Redis workers discoverable we need to set up a Service:

We’re not ready to deploy the guestbook’s frontend, written in PHP.

Before we create the service, we’re going to define type:LoadBalancer in the service configuration file:

To create the service, use:

Reviewing our services, we can see an external IP for our frontend service:

guestbook

Congratulations! You’ve deployed a multi-tiered application on a Kubernetes cluster!

What next?

This was a very basic deployment using a simple example application. In larger production deployments, there are many more considerations that you will need to take into account — security, networking and of course — monitoring and troubleshooting.

In a future article, we’ll show how to add the ELK Stack and Logz.io into the mix to help you gain visibility into your Kubernetes deployments on GKE.  

Gain visibility into your Kubernetes deployments with Logz.io.