Deploying Kubernetes on Google Kubernetes Engine

Tutorial 2 of 5

1. Introduction

In this tutorial, we will walk you through the process of deploying a Kubernetes cluster using Google Kubernetes Engine (GKE), Google Cloud's managed Kubernetes service.

By the end of this tutorial, you will:
- Understand what Google Kubernetes Engine is
- Learn how to create a Kubernetes cluster on GKE
- Deploy an application on the GKE cluster

Prerequisites:
- Basic understanding of Kubernetes
- An active Google Cloud Platform (GCP) account

2. Step-by-Step Guide

2.1 Google Kubernetes Engine (GKE)

GKE is a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The GKE environment consists of multiple machines (specifically, Compute Engine instances) grouped together to form a container cluster.

2.2 Creating a GKE Cluster

First, navigate to the GCP Console at https://console.cloud.google.com/. In the left-side menu, navigate to Kubernetes Engine > Clusters, then click Create Cluster.

You can customize your cluster by selecting the appropriate zone, machine type, and number of nodes. Once you've made your selections, click Create.

2.3 Deploying an Application

With your cluster created, you can now deploy an application. Navigate to the Workloads tab and click Deploy. You can either enter your container image URL or select one from the Container Registry. Once done, click Continue and then Deploy.

3. Code Examples

3.1 Creating a GKE Cluster

You can also create a GKE cluster using the gcloud command-line tool. Here's an example:

# Set your default compute zone
gcloud config set compute/zone us-central1-a

# Create a GKE cluster
gcloud container clusters create my-gke-cluster --num-nodes=3

In the above example, my-gke-cluster is the name of your Kubernetes cluster and --num-nodes=3 specifies that your cluster should consist of 3 nodes.

3.2 Deploying an Application

You can deploy an application using kubectl, the Kubernetes command-line tool. Here's an example:

# Create a deployment named 'hello-server' using the 'hello-app' container image
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

In this example, hello-server is the deployment name and gcr.io/google-samples/hello-app:1.0 is the container image.

4. Summary

In this tutorial, you've learned how to create a Kubernetes cluster on GKE and deploy an application to it. For further learning, explore how to manage your GKE cluster and how to scale your applications.

Additional Resources:
- Google Kubernetes Engine Documentation
- Kubernetes Documentation

5. Practice Exercises

  1. Create a GKE cluster with 5 nodes, and deploy the hello-app:2.0 container image to it.
  2. Scale your hello-server deployment to 3 replicas.
  3. Update your hello-server deployment to use the hello-app:1.0 container image.

Solutions, explanations, and further practice can be found in the GKE Documentation.