Introduction
In our previous article, we explored the benefits of Google Kubernetes Engine (GKE) and the distinction between its Autopilot and Standard modes. Now, it's time for action! In this article, we'll go through the process of setting up your very own GKE cluster, giving you a foundation to deploy your containerized applications.
There are two ways to deploy and manage clusters, via the Google Cloud console and the command shell. We'd take a look at both.
Prerequisites
Before we start, please ensure you have the following ready:
- Google Cloud account
Active Google Cloud Project: Your GKE cluster will live within a GCP project. If you don't have one, you'll need to create one.
Enable Kubernetes Engine API: To use the GKE, you need to enable this API.
Choosing Your Mode (Quick Recap)
Remember the key differences that determine which GKE mode is right for you:
Autopilot: Prioritizes ease of use and rapid deployment. Google handles most cluster management tasks for you.
Standard: Offers complete control over your cluster, from node configuration to Kubernetes settings. It demands more operational knowledge.
Walkthrough: Standard GKE Cluster
Method 1: Using the Google Cloud Console
Navigate to Kubernetes Engine: Find the Kubernetes Engine section within your Google Cloud Console.
Initiate Cluster Creation: Click the "Create Cluster" button and select "GKE Standard" as your cluster type.
Name and Location:
Name: Give your cluster a descriptive name.
Location: Select a zone or region suitable for your application's target audience and latency needs.
Configure Your Initial Node Pool:
Node machine type: Choose the virtual machine type that matches your workload requirements (CPU-optimized, memory-optimized, etc.).
Number of nodes: Specify how many nodes you want to start with.
Other options (optional): GKE offers a range of configurable options for the initial node pool (OS image, disk size, etc.). You can leave most as default.
Review and Create: Double-check your settings, then click "Create." The cluster creation process may take a few minutes.
Method 2: Using the gcloud
Command
This method gives us finer control over various aspects of the cluster configuration. Here's a basic example:
gcloud container clusters create my-first-cluster \
--zone=us-europe2-a \
--machine-type=n1-standard-2 \
--num-nodes=3 \
--network=default
Let's break it down:
gcloud container clusters create my-first-cluster
: This core command tells GKE to create a cluster named 'my-first-cluster'.--zone=us-europe2-a
: Specifies the zone where the cluster will reside.--machine-type=n1-standard-2
: Sets the machine type for nodes within our cluster.--num-nodes=3
: Starts the cluster with three nodes.--network=default
: Uses the default network within your Google Cloud Project.
Customization
This is a simplified example. gcloud
offers many flags to customize further: enabling specific Kubernetes features, configuring security settings, advanced networking, and more.
Walkthrough: Autopilot GKE Cluster
Method 1: Using the Google Cloud Console
Navigate to Kubernetes Engine: Find the Kubernetes Engine section within your Google Cloud Console.
Initiate Cluster Creation: Click the "Create Cluster" button and select "GKE Autopilot" as your cluster type.
Name and Location:
Name: Give your cluster a descriptive name.
Location: Select a zone or region for your cluster. Note: Autopilot supports only zonal clusters.
[Insert screenshots of name and location selection]
Click "Create": That's pretty much it! Google handles the rest. Cluster provisioning may take some minutes.
Method 2: Using the gcloud
Command
Here's a quick look at the gcloud
equivalent:
gcloud container clusters create my-autopilot-cluster \
--region=us-central1 \
--mode=autopilot
--region=us-central1
: Specifies the region as Autopilot is zonal only.--mode=autopilot
: Explicitly instructs GKE to use Autopilot mode.
Note that Autopilot sacrifices a great deal of control for the convenience of quick cluster deployment and management.