Kubernetes Engine (GKE) multi-cluster life cycle management series

Part V: GKE multi-cluster upgrades using Ingress for Anthos step-by-step tutorial

Ameer Abbas
Google Cloud - Community
18 min readApr 22, 2020

--

GKE Lifecycle Management using Ingress for Anthos

This tutorial describes how to upgrade a multi cluster GKE environment using the rolling upgrade strategy (discussed in the previous blog) and the multi cluster ingress feature provided by Ingress for Anthos. This tutorial is the culmination of the concepts covered in this blog series.

GCP recommends using the GKE Autoupgrade feature to upgrade your GKE clusters. Autoupgrade is a no-ops way of getting your clusters (master and nodes) automatically updated on a release schedule determined by GCP. This requires no intervention from the operator. However, in some cases, operators may want more control over how and when they upgrade clusters. This tutorial walks through a method of upgrading multiple clusters where your applications run on all clusters. It then utilizes the Ingress for Anthos (multicluster Ingress) feature to drain one cluster at a time before upgrading.

Prerequisites

  1. This tutorial requires multiple clusters (two or more) with the same applications (namespaces, deployments, services etc) running on all clusters.
  2. This tutorial assumes autoupgrade feature has been turned off for the clusters to be upgraded.
  3. This tutorial uses Ingress for Anthos. Ingress for Anthos requires:
  • GKE static versions 1.14.10-gke.17+ or GKE clusters in the Rapid or Regular release channels.
  • Clusters in VPC-Native (Alias IP) mode. For more information, see Creating a VPC-native cluster.
  • Have HTTP load balancing enabled (enabled by default).
  • gcloud — version must be 281 or higher. GKE cluster registration steps depend on this version or higher.

Topology

This tutorial uses the following topology. There are a total of three clusters. Two clusters (blue and green) act as identical clusters with the same application deployed. One cluster (ingress-config) acts as the control plane cluster which configures Ingress for Anthos. In this tutorial, you deploy a sample app called the Hipster Shop app on two application clusters (blue and green clusters). Hipster Shop app is a sample microservices application comprising ten microservices simulating an e-commerce application. It consists of a web frontend (that clients can access) and a number of backend Services for example shopping cart, product catalog and recommendation services simulating a cloud-native e-retailer.

GKE Lifecycle Management using Ingress for Anthos

Objectives

  • Create three GKE clusters.
  • Register the clusters to GKE Hub.
  • Configure one GKE cluster (ingress-config) as the central config cluster. This cluster acts as the control plane for multi cluster ingress. It creates and manages the resources for Ingress for Anthos.
  • Deploy a sample application to the other GKE clusters. Use the Hipster Shop app as the sample application.
  • Configure Ingress for Anthos to send client traffic to the Hipster Shop running on both application clusters.
  • Set up a load generator to Hipster Shop app and configure monitoring with Cloud Monitoring.
  • Remove (drain) one application cluster from multi cluster ingress.
  • Upgrade the drained cluster.
  • Spill traffic back to the newly upgraded cluster using Ingress for Anthos.

Costs

This tutorial uses the following billable components of Google Cloud Platform:

  • GKE
  • Networking
  • Load Balancing
  • Cloud Monitoring

Use the Pricing Calculator to generate a cost estimate based on your projected usage.

Before you begin

  • Select or create a GCP project.
  • Enable billing for your project.
  • You run all the terminal commands in this tutorial from Cloud Shell. Open Cloud Shell:
  • Set your default project.
  • Enable the GKE, GKE Hub and multiclusteringress APIs in the project.

When you finish this tutorial, you can avoid continued billing by deleting the resources you created. See Cleaning up for more detail.

Set up the environment

You run all the terminal commands in this tutorial from Cloud Shell.

  • Open Cloud Shell:
  • Clone the repo to get the files for this tutorial. Create a WORKDIR. This way you can delete the WORKDIR at the end of this tutorial.

Create and register GKE clusters to GKE Hub

Create GKE clusters

  • Create three GKE clusters.
  • Wait a few minutes until all clusters are successfully created. Ensure that the clusters are running:

Master/node version and IP addresses may be different.

  • Create a new kubeconfig file and connect to all clusters to generate entries in the kubeconfig file:

You use the kubeconfig file to create authentication to clusters by creating a user and context for each cluster. After you create the kubeconfig file, you can quickly switch context between clusters.

  • Verify that you have three clusters in the kubeconfig file:
  • Get the context for the three clusters for use later.

Register GKE clusters to GKE Hub

GKE Hub enables you to operate your Kubernetes clusters in hybrid environments. GKE Hub also enables registered clusters to use advanced GKE features for example Ingress for Anthos. You need a GCP Service Account (SA) to register a GKE cluster to GKE Hub. Give IAM permission to the GCP SA to be able to register to GKE Hub.

  • Create a GCP service account and download its credentials to use for registering the cluster.
  • Get the URIs from the GKE clusters.
  • Register the three clusters to the GKE Hub.
  • Verify that the clusters are registered.
  • Configure the ingress-config cluster as the config cluster for Ingress for Anthos. You do this by enabling multiclusteringress feature through the GKE Hub.

Running the command above adds the MulticlusterIngress and MulticlusterService CRDs to the config cluster.

  • The previous command takes a few minutes to complete. Run the following command to verify that the ingress-cluster has been successfully configured for Ingress for Anthos. Wait a few moments until you see code: OK for the ingress-config cluster (as shown below).

While lifecycleState is marked as enabled, this feature is not ready to use until your config cluster has an OK status. If you do not see code: OK after a few minutes, go to the troubleshooting section. When the feature is not ready you should see the following output.

Press CTRL-C or CMD-C on a Macbook to exit the watch command.

Deploy Hipster Shop app to blue and green clusters

  • Deploy the Hipster Shop app to both blue and green clusters.
  • Wait a few minutes and ensure all Pods are Running in the blue and green clusters.

Configure multi cluster Ingress

In this section, you create a multicluster Ingress that sends traffic to the Hipster Shop frontend to both blue and green clusters. A Google Cloud Load Balancer (GCLB) is created which uses the frontend Services in both blue and green clusters as backends. To create the GCLB, you need two resources: a MultiClusterIngress and one or more MultiClusterServices. MultiClusterIngress and MultiClusterService objects are multi-cluster analogs to the existing Kubernetes Ingress and Service resources used in the single cluster context.

  • Deploy the MulticlusterIngress resource to the ingress-config cluster.
  • Deploy the MulticlusterService resource to the ingress-config cluster.
  • Inspect the MulticlusterIngress resource.

MulticlusterIngress resource looks very much like the Kubernetes Ingress resource except that the serviceName spec points to a MulticlusterService.

  • Inspect the MulticlusterService resource.

MulticlusterService looks like a Kubernetes Service resource, except it has a clusters spec. The clusters value is the list of registered clusters where the MulticlusterService is created.

  • The MulticlusterIngress creates a GCLB in the project with a backend service pointing to the MulticlusterService. Wait until you see a public VIP for the GCLB. Run the following command until you see the GCLB VIP in the status.

This step takes a few minutes. Do not proceed until you see a VIP assigned in the MulticlusterIngress status. Until the GCLB VIP is created, you will see null as the output for the command above.

  • Press CTRL-C or CMD-C on a Macbook to exit the watch command.
  • Access the Hipster Shop app by navigating to the IP address on the GCLB VIP from the previous step.
Hipster Shop frontend

If you see a 404 error message, wait a bit longer and refresh the page until you see the Hipster shop frontend.

Browse through the app and make a few purchases. At this point the Hipster Shop app is deployed to both blue and green clusters and the MulticlusterIngress is set up to send traffic to both clusters.

Set up load generator

In this section, you set up a loadgenerator that generates client traffic to the GCLB VIP. Initially, this sends traffic to both blue and green clusters since the MulticlusterService is set up to send traffic to both clusters. Later, you configure the MulticlusterService to send traffic to a single cluster.

  • Get the GCLB VIP.
  • Configure the loadgenerator to send client traffic to the GCLB VIP.
  • Deploy the loadgenerator in the ingress-config cluster.
  • Verify loadgenerator Pod is Running in the ingress-config cluster.

Monitor with Cloud Monitoring

In this section you monitor the traffic to the Hipster Shop app using Cloud Monitoring and Cloud Console.

Monitoring GCLB metrics with Cloud Console

In the previous section, you set up a loadgenerator deployment that simulates Hipster Shop client traffic by accessing it through the GCLB VIP. You can monitor GCLB metrics through the Cloud Console.

  • Get the name of the forwarding rule for the frontend-multicluster-ingress.
  • Navigate to the link from the output of the command below.

You can also get to this page via the Cloud Console by navigating to Network services > Load balancing page. Click on the forwarding rule that starts with ‘mci’ and then click on the Monitoring tab.

  • In the Load balancer details Monitoring page, select the backend beginning with mci from the Backend dropdown menu.
Google Cloud Load Balancer Monitoring
  • You can see that the traffic to the Hipster Shop app is going to both blue and green clusters (noted by the two zones the clusters are in). You can also see the timeline metrics chart showing traffic going to both backends.
Google Cloud Load Balancer Monitoring

It takes a few minutes for load balancer metrics to populate. Refresh the page after a few minutes if needed.

You can see the NEGs (under the Backend label starting with k8s1-) for the two frontend MulticlusterServices running in both the blue and green cluster.

Monitoring with Cloud Monitoring

You can monitor the metrics of your applications via Cloud Monitoring.

  • Navigate to the link from the output of the command below to access Cloud Monitoring metric explorer.

You can also access the same page via the Cloud Console. Click on Monitoring > Metrics explorer. In the Find resource type and metrics search bar, type and select `https_lb_rule`. For Select a metric, search for and select `Request count`. In the Group by search bar, search for and select `backend_scope`.

  • When accessing the link for the first time, Cloud Monitoring sets up a new workspace for you.
  • After the workspace is created, the chart shows the GCLB Request Count metrics grouped by backends.
Cloud Monitoring Metrics Explorer

You see traffic going to the two backends (blue and green clusters). The backends are represented by the zones for the two frontend MulticlusterServices running in both clusters.

You may see a third backend (named INVALID_BACKEND) for a short period of time. This is a UI anomaly in Cloud Monitoring and can be ignored.

Drain and upgrade the green cluster

In this section, you “drain” the green cluster. Draining a cluster means you remove it from the load balancing pool. After you drain the green cluster, all client traffic destined for the Hipster Shop app goes to the blue cluster. You can monitor this process as described in the previous section. Once the cluster is drained, you can upgrade the drained cluster. After the upgrade, you can put it back in the load balancing pool. You follow the same steps to upgrade the other cluster (not shown in this tutorial).

To drain the green cluster, you update the MulticlusterService resource in the ingress-cluster and remove the green cluster from the clusters spec.

Drain the green cluster

  • Update the MulticlusterService resource in the ingress-config cluster.
  • Verify that you only have the blue cluster in the clusters spec.

You see only the blue cluster in the clusters spec. This means only the blue cluster is in the GCLB load balancing pool.

Monitor Ingress metrics

  • Navigate to the Cloud Monitoring metrics chart page or by clicking the output of the following command.
  • The output shows that only the blue cluster is receiving traffic.
Cloud Monitoring

It may take a few minutes for Cloud Monitoring metrics to refresh.

  • You also see similar metrics from the GCLB metrics in the Cloud Console. Navigate to the GCLB Monitoring metrics page in Cloud Console or click on the output of the following command.
  • The chart also shows only the blue cluster is receiving Hipster Shop traffic.
Google Cloud Load Balancer Monitoring

It may take a few minutes for load balancer metrics to refresh.

Upgrade the green cluster

Now that the green cluster is no longer receiving any client traffic, you can upgrade the cluster (master and nodes). Get the current cluster version for the master and the nodes. You can then find the available versions (in the zone). Finally, you can upgrade the cluster to the newer version.

  • Get the current version of the clusters.

Your cluster versions may be different depending on the time you go through this tutorial.

  • Get the list of available master versions in the zone.
  • Get a list of available node versions in the zone.
  • Pick the desired master and node version (higher than the current master and node version) for the green cluster.

Your cluster versions may be different depending on the time you go through this tutorial. In order to determine which versions to pick, refer to the upgrading clusters and node pools documentation. Generally, it is best practice to pick the same version for the master and the nodes. Pick one of the available versions in your list for both master and node.

  • Upgrade the master for the green cluster.
  • Type “Y” to confirm the upgrade.

This process takes a few minutes to complete. Please wait until the master upgrade is complete before proceeding. Once the update is complete, you should see the following message.

Updated [https://container.googleapis.com/v1/projects/gke-multicluster-upgrades/zones/us-west1-c/clusters/green].

  • Once the master upgrade is completed, you can upgrade the nodes in the green cluster by running the following command.
  • Type “Y” to confirm the upgrade.

This process takes a few minutes to complete. Please wait until the node upgrade is complete before proceeding. After the upgrade is complete, you should see the following message.

Upgrading green… Done with 4 out of 4 nodes (100.0%): 4 succeeded…done.

Updated [https://container.googleapis.com/v1/projects/gke-multicluster-upgrades/zones/us-west1-c/clusters/green].

  • Verify that the green cluster (master and nodes) are upgraded.

Your cluster versions may be different depending on the time you go through this tutorial.

Add green cluster to the load balancing pool

In this section, you add the green cluster back in the load balancing pool.

  • Verify that all Hipster Shop app deployments are running on the green cluster prior to adding it back to the load balancing pool.
  • Update the MutliclusterService to add the green cluster back in the load balancing pool.
  • Verify that you have both blue and green clusters in the clusters spec.

You see both blue and green clusters in the clusters spec.

Monitor Ingress metrics

  • Navigate to the Cloud Monitoring metrics chart page or by clicking the output of the following command.
  • The output shows that both blue and green clusters are receiving traffic.
Cloud Monitoring

It may take a few minutes for Monitoring metrics to refresh.

  • You also see similar metrics from the GCLB metrics in the Cloud Console. Navigate to the GCLB Monitoring metrics page in Cloud Console or click on the output of the following command.

The chart also shows both blue and green clusters are receiving Hipster Shop traffic.

Google Cloud Load Balancer Monitoring

It may take a few minutes for load balancer metrics to refresh.

Congratulations. You successfully upgraded a GKE cluster in a multi cluster architecture using Ingress for Anthos. You can upgrade the blue cluster using the same process.

Cleaning up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this tutorial:

Delete clusters

  • Unregister and delete blue and green clusters.
  • Delete the MuticlusterIngress from the ingress-config cluster. This deletes the GCLB resources from the project. Unregister and delete the ingress-config cluster.
  • Verify all clusters are deleted.
  • Unset the kubeconfig file. This resets to the default kubeconfig file.
  • Remove the WORKDIR folder.

Delete the project

The easiest way to eliminate billing is to delete the project you created for the tutorial.

To delete the project:

  • In the Cloud Platform Console, go to the Projects page.
  • In the project list, select the project you want to delete and click Delete.
Google Cloud Console
  • In the dialog, type the project ID, and then click Shut down to delete the project.

What’s next

--

--

Ameer Abbas
Google Cloud - Community

I do Cloud architecture, Kubernetes, Service Mesh, CI/CD and other cloud native things. Solutions Architect at Google Cloud. Opinions stated here are my own.