What Is Google Kubernetes Engine (GKE)? Beginner Guide | Rafay
What Is Google Kubernetes Engine (GKE)? A Beginner’s Guide
Google Kubernetes Engine (GKE) is a managed environment for deploying, managing and scaling containerized applications using the Google Cloud Platform infrastructure. The environment that Google Kubernetes Engine provides consists of multiple machines, specifically Google Compute Engine instances, which are grouped together to form a cluster. Google Kubernetes Engine draws on the same reliable infrastructure and design principles that run popular Google services and provides the same benefits like automatic management, monitoring and liveness probes for application containers, automatic scaling, rolling updates, and more.
Overview
This guide is designed to help you to get started with Google Kubernetes Engine(GKE). We will be using the Google cloud shell to setup the GKE cluster and host a multi-container application. This guide will walk through the steps to:
- Prerequisites
- Creating Clusters
- Administering Cluster
- Configuring and expanding Clusters
- Deploying workloads to clusters
- Deploying applications
Prerequisites
In this section, we will enable the Kubernetes Engine API. Along with this we will setup a cloud shell and Local shell for deploying the Kubernetes Cluster. Choosing a Shell To complete this tutorial, you can either use a cloud shell or local Linux terminal.
Cloud Shell
Cloud Shell is a shell environment for managing resources hosted on Google Cloud. Cloud Shell comes preinstalled with the gcloud command-line tool and kubectl command-line tool. The gcloud tool provides the primary command-line interface for Google Cloud, and kubectl provides the primary command-line interface for running commands against Kubernetes clusters. To launch Cloud shell, perform the following steps.
- Go to Google cloud console with your gmail account ( https://console.cloud.google.com) Link.
- From the upper-right corner of the console, click the Activate Cloud Shell.
Local Shell
If you prefer using your local shell, you must install the gcloud tool and kubectl tool in your environment. To install gcloud and kubectl, perform the following steps:
- Install the Cloud SDK, which includes the gcloud command-line tool.
Creating a GKE cluster
A cluster consists of at least one cluster master machine and multiple worker machines called nodes. Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster. You deploy applications to clusters, and the applications run on the nodes.
Creating a single-zone cluster
To create a cluster with the gcloud command-line tool, use one of the following gcloud container clusters commands.
Creating a multi-zonal cluster
To create a multi-zonal cluster, set --zone to the zone for the cluster control plane, and set --node-locations to a comma-separated list of compute zones where the control plane and nodes are created. Use one of the following commands.
Administering Cluster
Viewing your clusters
To view a specific cluster, run the following command:
Setting a default cluster for gcloud
To set a default cluster for gcloud commands.
Configuring cluster access for Kubectl
To run kubectl commands against a cluster created in Cloud Console, from another computer, or by another member of the project, you need to generate a kubeconfig entry in your environment. Generate a kubeconfig entry by running the following command:
Upgrading the cluster
You can manually upgrade your cluster using the Cloud Console or the gcloud command-line tool. To upgrade to the latest version, run the following command:
Resizing a Cluster
You can resize a cluster to increase or decrease the number of nodes in that cluster. To increase the size of your cluster.
Deploying workloads to clusters
To deploy and manage your containerized applications and other workloads on your GKE cluster, you use the Kubernetes system to create Kubernetes controller objects. These controller objects represent the applications, daemons, and batch jobs running on your clusters. You can create these controller objects using the Kubernetes API or by using kubectl, a command-line interface to Kubernetes installed by gcloud. Typically, you build a representation of your desired Kubernetes controller object as a YAML configuration file, and then use that file with the Kubernetes API or the kubectl command-line interface.
Types of workloads
Kubernetes provides different kinds of controller objects that correspond to different kinds of workloads you can run. The following sections describe some common types of workloads and the Kubernetes controller objects you can create to run them on your cluster, including:
- Stateless applications: A stateless application does not preserve its state and saves no data to persistent storage.
- Stateful applications: A stateful application requires that its state be saved or persistent.
- Batch jobs: Batch jobs represent finite, independent, and often parallel tasks which run to their completion.
- Daemons: Daemons perform ongoing background tasks in their assigned nodes without the need for user intervention.
Deploy a stateless application
Stateless applications are applications which do not store data or application state to the cluster or to persistent storage.
Creating a Deployment
The following is an example of a simple Deployment manifest file. This Deployment creates three replicated Pods labelled app=my-app that run the hello-app image stored in Container Registry:
You can declaratively create and update Deployments from manifest files using kubectl apply.
Deploying a stateful application
Stateful applications save data to persistent disk storage for use by the server, by clients, and by other applications.
Requesting persistent storage in a StatefulSets
Applications can request persistent storage with a PersistentVolumeClaim persistent disk storage.
Deploying a containerized web application
This tutorial shows you how to package a web application in a Docker container image, and run that container image on a Google Kubernetes Engine cluster as a load-balanced set of replicas that can scale to the needs of your users.
Build the container image
GKE accepts Docker images as the application deployment format. To build a Docker image, you need to have an application and a Dockerfile. For this tutorial, you will deploy a sample web application called hello-app.
Upload the container image
You need to upload the container image to a registry so that GKE can download and run it. First, configure Docker command-line tool to authenticate to Container Registry.
Run your container locally
To test your container image using your local Docker engine, run the following command:
Deploy your application
To deploy and manage applications on a GKE cluster, you must communicate with the Kubernetes cluster management system.
Expose your application to the Internet
By default, the containers you run on GKE are not accessible from the Internet, because they do not have external IP addresses.
Scale up your application
You add more replicas to your application's Deployment resource by using the kubectl scale command. To add two additional replicas to your Deployment.
Deploy a new version of your app
GKE's rolling update mechanism ensures that your application remains up and available even as the system replaces instances of your old container image.
Conclusion
In this guide you have seen how easily we build a GKE cluster on Google environment. GKE offers a platform for managing your containers across a variety of operating environments, significantly reducing the time necessary to build, deploy, and scale them.