This tutorial is intended for cloud architects and operations administrators interested in deploying a web application to a Google Kubernetes Engine (GKE) cluster and exposing it with an HTTPS load balancer.
Objectives
In this tutorial, you will learn how to:
- Create a GKE cluster.
- Create a global IP address and Cloud DNS zone with Terraform.
- Configure HTTPS load balancing.
- Deploy a sample web application.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage,
use the pricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.
Before you begin
Set up your project
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Google Kubernetes Engine, Cloud DNS APIs.
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Google Kubernetes Engine, Cloud DNS APIs.
- You must own a domain name. The domain name must be no longer than 63 characters. You can use Google Domains or another registrar.
Set up your environment
In this tutorial, you use Cloud Shell to manage resources hosted on
Google Cloud. Cloud Shell is preinstalled with the software you need for
this tutorial, including
Terraform,
kubectl
and the
gcloud CLI.
Set environment variables:
PROJECT_ID=$(gcloud config get-value project) gcloud config set project $PROJECT_ID gcloud config set compute/region us-central1
Clone the code repository:
git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples.git
Change to the working directory:
cd kubernetes-engine-samples/autopilot/networking-tutorial
Create a GKE cluster
The following Terraform file creates a GKE cluster:
The following Terraform file creates a global IP address and Cloud DNS zone:
Initialize Terraform:
terraform init
View the infrastructure changes:
terraform plan
When prompted, enter your domain, such as
my-domain.net
.Apply the Terraform configuration:
terraform apply --auto-approve
When prompted, enter your domain, such as
my-domain.net
.The output is similar to the following:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: cluster_name = "networking-cluster" region = "us-central1"
Create an external Application Load Balancer
The following manifest describes a ManagedCertificate, FrontendConfig, Deployment, Service, and Ingress:
Replace
DOMAIN_NAME
with your domain name, such asmy-domain.net
.This manifest has the following properties:
networking.gke.io/managed-certificates
: the name of the ManagedCertificate.networking.gke.io/v1beta1.FrontendConfig
: the name of the FrontendConfig resource.kubernetes.io/ingress.global-static-ip-name
: the name of the IP address.kubernetes.io/ingress.class
: instructs the GKE Ingress controller to create an external Application Load Balancer.
Apply the manifest to your cluster:
kubectl apply -f kubernetes-manifests.yaml
Verify the Ingress was created:
kubectl describe ingress frontend
The output is similar to the following:
... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ADD 2m loadbalancer-controller default/frontend Normal CREATE 1m loadbalancer-controller ip: 203.0.113.2 ...
It might take several minutes for the Ingress to provision.
Test application
Check the status of the SSL certificate:
kubectl get managedcertificates.networking.gke.io networking-managed-cert
The SSL certificate might take up to 30 minutes to provision. The following output indicates the SSL certificate is ready:
NAME AGE STATUS networking-managed-cert 28m Active
Run a
curl
command:curl -Lv https://DOMAIN_NAME
The output is similar to the following:
* Trying 34.160.115.33:443... * Connected to DOMAIN_NAME (34.160.115.33) port 443 (#0) ... * TLSv1.3 (IN), TLS handshake, Certificate (11): ... * Server certificate: * subject: CN=DOMAIN_NAME ... > Host: DOMAIN_NAME
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the project
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Delete individual resources
Delete the kubernetes resources:
kubectl delete -f kubernetes-manifests.yaml
Delete the Terraform resources:
terraform destroy --auto-approve
When prompted, enter your domain, such as
my-domain.net
.
What's next
- Learn more about GKE networking.