This lab shows you how to enable, use and deploy the multi-cluster GKE Gateway
controller, a Google-hosted controller that provisions external and internal
load balancers, which balance traffic across multiple Kubernetes clusters.
In GKE the gke-l7-gxlb-mc and gke-l7-rilb-mc GatewayClasses deploy
multi-cluster Gateways that provide HTTP routing, traffic splitting, traffic
mirroring, health-based failover, and more across different GKE clusters,
Kubernetes Namespaces, and across different regions. Multi-cluster Gateways
make managing application networking across many clusters and teams easy,
secure, and scalable for infrastructure administrators.
Objectives
In this lab, you learn how to perform the following tasks:
Register GKE clusters to an Anthos Fleet
Enable and configure Multi-cluster Services (MCS)
Enable and configure Multi-clusster Gateways (MCG)
Deploy a distributed application and balance traffic accross clusters
Setup and requirements
In this task, you use Qwiklabs and perform initialization steps for your lab.
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Google Cloud Platform Console
After you complete the initial sign-in steps, the project dashboard appears.
Click Select a project, highlight your GCP Project ID, and click
OPEN to select your project.
Activate Google Cloud Shell
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Note:
Full documentation of gcloud is available in the
gcloud CLI overview guide
.
Note: The lab environment has already been partially configured:
A GKE cluster named gke-west-1 has been created
A GKE cluster named gke-west-2 has been created
A GKE cluster named gke-east-1 has been created
Task 1. Configure access for kubectl and verify the cluster
3 Google Kubernetes Engine (GKE) clusters have already been created. You are
going to setup access to these clusters.
In Cloud Shell, set environment variables for use in scripts using the
following commands:
Confirm that the clusters have successfully registered with an Anthos Fleet:
gcloud container fleet memberships list --project=${PROJECT_ID}
Output:
NAME EXTERNAL_ID
gke-east-1 657e835d-3b6b-4bc5-9283-99d2da8c2e1b
gke-west-2 f3727836-9cb0-4ffa-b0c8-d51001742f19
gke-west-1 93de69c0-859e-4ddd-bf3a-e3d62ef5090b
Task 3. Enable Multi-cluster Services (MCS)
In this task, you enable Multi-cluster Services (MCS) in your fleet for the
registered clusters. MCS controller listens for import/export Services, so that
Kubernetes Services are routable across clusters and traffic can be distributed
across them.
Enable multi-cluster Services in your fleet for the registered clusters:
Confirm that MCS is enabled for the registered clusters. You will see the
memberships for the three registered clusters. It may take several minutes for
all of the clusters to show. Wait and retry until you see a similar output.
Click Check my progress to verify the objective.
Enable Multi-cluster Services (MCS) and grant the required IAM roles.
Task 4. Enable the Multi-cluster Gateway (MCG) controller
Before using Gateway resources in GKE, you must enable the Multi-cluster Gateway (MCG) controller.
The config cluster is the GKE cluster in which your Gateway and Route resources
are deployed. It is a central place that controls routing across your clusters.
You will use gke-west-1 as your config cluster.
Enable the Multi-cluster Gateway controller for the gke-west-1 cluster:
NAME CONTROLLER
gke-l7-gxlb networking.gke.io/gateway
gke-l7-gxlb-mc networking.gke.io/gateway
gke-l7-rilb networking.gke.io/gateway
gke-l7-rilb-mc networking.gke.io/gateway
Four Gateway classes have been installed. The gke-l7-gxlb-mc for external
multi-cluster Gateways and gke-l7-rilb-mc for internal multi-cluster
Gateways. The other two are used for single cluster deployments.
Congratulations! You can now create multi-cluster Gateways using these Gateway classes.
Click Check my progress to verify the objective.
Enable the MCG controller and grant the IAM permissions required by the Gateway controller.
Task 5. Deploy the demo application
Create the store Deployment and Namespace in the gke-east-1 and
gke-west-2. The config cluster can also host workloads, but in this lab, you
only run the Gateway controllers and configuration on it:
Notice that we are sending the default requests to the closest backend
defined by the default rule. In case that the path /west is in the
request, the request is routed to the service in gke-west-2. If the
request's path matches /east, the request is routed to the gke-east-1
cluster.
View the status of the Gateway that you just created in gke-west-1:
kubectl describe gateway external-http --context gke-west-1 --namespace store
Status:
Addresses:
Type: IPAddress
Value: 35.186.207.183
Conditions:
Last Transition Time: 2022-08-22T09:33:06Z
Message:
Reason: Scheduled
Status: True
Type: Scheduled
Last Transition Time: 2022-08-22T09:38:54Z
Message:
Reason: Ready
Status: True
Type: Ready
Listeners:
Attached Routes: 1
Conditions:
Last Transition Time: 2022-08-22T09:38:54Z
Message:
Reason: Ready
Status: True
Type: Ready
Name: http
Supported Kinds:
Group: gateway.networking.k8s.io
Kind: HTTPRoute
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ADD 10m mc-gateway-controller store/external-http
Normal SYNC 8m39s mc-gateway-controller store/external-http
Warning SYNC 8m20s mc-gateway-controller failed to translate Gateway "store/external-http": error getting ServiceImportConfig gw-serve404.kube-system: serviceimportconfigs.net.gke.io "gw-serve404.kube-system" not found
Warning SYNC 6m19s mc-gateway-controller failed to translate Gateway "store/external-http": Error GWCER104: HTTPRoute "store/public-store-route" is misconfigured, err: Error GWCER102: serviceimports store/store-east-1 not found..
Normal UPDATE 2m32s (x3 over 10m) mc-gateway-controller store/external-http
Normal SYNC 119s (x2 over 2m32s) mc-gateway-controller SYNC on store/external-http was a success
Sometimes there are transient errors shown in the Events section. Wait till
it shows the follwoing message: "SYNC on store/external-http was a success".
It might take up to 10 minutes to sync.
It takes some time for the external IP to be created. To ensure that it is, run this command until you see the external IP.
kubectl get gateway external-http -o=jsonpath="{.status.addresses[0].value}" --context gke-west-1 --namespace store | xargs echo -e
If it doesn't return an external IP, wait for a few minutes and run it again.
If you see the following message: "default backend - 404" or "curl: (52)
Empty reply from server", the Gateway is not ready yet. Wait a couple of
minutes and try again.
Access the application located in the gke-west-2 cluster:
Click Check my progress to verify the objective.
Deploy the Gateway and HTTPRoutes.
Congratulations!
In this lab, you registered the pre-created GKE clusters to an Anthos Fleet,
enabled and configured the Multi-cluster Services (MCS) and Multi-cluster
Gateways (MCG) controllers, deployed Gateways and HTTPRoutes in the config
cluster, and run a distributed application across multiple clusters with a
unique Load Balancer routing the traffic to the right pods.
End your lab
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
1 star = Very dissatisfied
2 stars = Dissatisfied
3 stars = Neutral
4 stars = Satisfied
5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.