
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create Pods and services to test DNS resolution
/ 10
Deploy a sample workload and a ClusterIP service
/ 10
Convert the service to use NodePort
/ 20
Create static public IP addresses using GCP Networking
/ 20
Deploy a new set of Pods and a LoadBalancer service
/ 20
Deploy an Ingress resource
/ 20
In this lab, you will create two deployments of Pods and work with three different types of services, including the Ingress resource, and explore how Kubernetes services in GKE are associated with Google Cloud Network Load Balancers.
In this lab, you learn how to perform the following tasks:
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.
After you complete the initial sign-in steps, the project dashboard appears.
You will do most of the work for this lab in Cloud Shell.
After a moment of provisioning, the Cloud Shell prompt appears.
In this task, you connect to the lab GKE cluster and create a deployment manifest for a set of Pods within the cluster that you will then use to test DNS resolution of Pod and service names.
You will create a service called dns-demo
with two sample application Pods called dns-demo-1
and dns-demo-2
.
The pods that you will use to test network connectivity via Kubernetes services are deployed using the dns-demo.yaml
manifest file that has been provided for you in the source repository. You will use these pods later to test connectivity via various services from systems inside your Kubernetes cluster.
You will also test connectivity from external addresses using the Cloud Shell. You can use the Cloud Shell for this because it is on a network that is completely separate to your Kubernetes cluster networks.
The output should look like this example.
Output:
Click Check my progress to verify the objective.
bash
running from dns-demo-1:Now that you are inside a container in the cluster, subsequent commands will run from that context and you will use this to test network connectivity by pinging various targets in later tasks. However, you don't have a tool to ping in this container, so you need to install the ping
command first.
apt-get
and install a ping
tool:This ping should succeed and report that the target has the ip-address you found earlier for the dns-demo-2
Pod.
dns-demo
service's FQDN, instead of a specific Pod inside the service:This ping should also succeed but it will return a response from the FQDN of one of the two demo-dns Pods. This Pod might be either demo-dns-1
or demo-dns-2
.
When you deploy applications, your application code runs inside a container in the cluster, and thus your code can access other services by using the FQDNs of those services from inside that cluster. This approach is simpler than using IP addresses or even Pod names, because those are more likely to change.
In this task, you create a deployment manifest for a set of Pods within the cluster and then expose them using a ClusterIP service.
In this task you will deploy a sample web application container image that listens on an HTTP server on port 8080 using the following manifest that has already been created for you in the hello-v1.yaml
manifest file.
A second Cloud Shell session appears in your Cloud Shell window. You can switch sessions by clicking them in the menu bar.
hello-v1.yaml
file, execute the following command:The output should look like this example.
Output:
In this task you will deploy a Service using a ClusterIP using the hello-svc.yaml
sample manifest that has already been created for you.
This manifest defines a ClusterIP service and applies it to Pods that correspond to the selector. In this case, the manifest is applied to the hello-v1 Pods that you deployed. This service will automatically be applied to any other deployments with the name: hello-v1
label.
Your IP address might be different from the example output.
Output:
No external IP is allocated for this service. Because the Kubernetes Cluster IP addresses are not externally accessible by default, creating this service does not make your application accessible outside of the cluster.
Click Check my progress to verify the objective.
The connection should fail because that service is not exposed outside of the cluster.
Output:
Now you will test the service from inside the cluster using the interactive shell you have running on the dns-demo-1
Pod.
dns-demo-1
Pod.curl
so you can make calls to web services from the command line:This connection should succeed and provide a response similar to the output below. Your hostname might be different from the example output.
Output:
This connection works because the clusterIP can be resolved using the internal DNS within the Kubernetes Engine cluster.
In this task, you will convert your existing ClusterIP service to a NodePort service and then retest access to the service from inside and outside the cluster.
A modified version of the hello-svc.yaml file called hello-nodeport-svc.yaml
that changes the service type to NodePort has already been created for you.
hello-svc
to NodePort, execute the following command:This manifest redefines hello-svc
as a NodePort service and assigns the service port 30100 on each node of the cluster for that service.
Your IP address might be different from the example output.
Output:
Click Check my progress to verify the objective.
The connection should fail because that service is not exposed outside of the cluster.
Output:
Now you will test the service from another Pod.
This connection should succeed and provide a response similar to the output below. Your hostname might be different from the example output.
Output:
This connection works because the clusterIP can be resolved using the internal DNS within the GKE cluster.
In the Google Cloud Console navigation menu, navigate to Networking > VPC Network > IP Addresses.
Click Reserve External Static Address.
Enter regional-loadbalancer
for the Name.
Explore the options but leave the remaining settings at their defaults. Note that the default type is Regional.
Click Reserve.
Make a note of the external ip-address called regional-loadbalancer
. You will use this in a later task.
Click Reserve External Static Address.
Enter global-ingress
for the Name.
Change the Type to Global.
Leave the remaining settings at their defaults.
Click Reserve.
Make a note of the external ip-address called global-ingress
. You will use this in a later task.
Click Check my progress to verify the objective.
You will now deploy a new set of Pods running a different version of the application so that you can easily differentiate the two services. You will then expose the new Pods as a LoadBalancer service and access the service from outside the cluster.
A second Deployment manifest called hello-v2.yaml
has been created for you that creates a new deployment that runs version 2 of the sample hello application on port 8080.
hello-v2
deployment execute the following command:The output should look like this example.
Output:
In this task you will deploy a LoadBalancer Service using the hello-lb-svc.yaml
sample manifest that has already been created for you.
You will use the sed command to replace the 10.10.10.10 placeholder address in the load balancer yaml file with the static address you reserved earlier for the load balancer.
Make sure you are still in the second Cloud Shell window. This is the window NOT connected to the stdin and stdout of the dns-test Pod.
Enter the following command in the Cloud Shell to save the regional static IP-address you created earlier into an environment variable:
Enter the following command in the Cloud Shell to replace the placeholder address with the regional static IP-address:
The loadBalancerIP
should match the address you recorded earlier for the regional-loadbalancer
reserved static ip-address.
This manifest defines a LoadBalancer service, which deploys a Google Cloud Network Load Balancer to provide external access to the service. This service is only applied to the Pods with the name: hello-v2
selector.
Your IP address might be different from the example output.
Output:
Notice that the new LoadBalancer service lists the regional-loadbalancer
reserved address as its external IP address. In GKE environments the external load balancer for the LoadBalancer service type is implemented using a Google Cloud load balancer and will take a few minutes to create. This external IP address makes the service accessible from outside the cluster.
You should see a TCP Load Balancer listed with 1 target pool backend and 2 instances.
The details should show that it is a regional TCP load balancer using the static IP address you called regional-loadbalancer
when you reserved it earlier.
Click Check my progress to verify the objective.
The connection should fail because that service name is not exposed outside of the cluster.
Output:
This occurs because the external IP address is not registered with this hostname.
[external_IP]
with your service's external IP address:Example:
This time the connection does not fail because the LoadBalancer's external ip-address can be reached from outside Google Cloud.
Output:
dns-demo-1
Pod.This connection should succeed and provide a response similar to the output below. Your hostname will be different from the example output.
Output:
The internal DNS name works within the Pod, and you can see that you are accessing the same v2 version of the application as you were from outside of the cluster using the external ip address.
[external_IP]
with your service's external IP address:Example:
Output:
The external IP also works from inside Pods running in the cluster, and returns a result from the same v2 version of the applications.
This will return you to the Cloud Shell command prompt.
You have two services in your cluster for the hello application. One service is hosting version 1.0 via a NodePort service, while the other service is hosting version 2.0 via a LoadBalancer service. You will now deploy an Ingress resource that will direct traffic to both services based on the URL entered by the user.
Ingress is a Kubernetes resource that encapsulates a collection of rules and configuration for routing external HTTP(S) traffic to internal services.
On GKE, Ingress is implemented using Cloud Load Balancing. When you create an ingress resource in your cluster, GKE creates an HTTP(S) load balancer and configures it to route traffic to your application.
A sample manifest called hello-ingress.yaml
that will configure an ingress resource has been created for you.
This configuration file defines an ingress resource that will attach to the global-ingress
static ip-address you created in a previous step. This ingress resource will create a global HTTP(S) load balancer that directs traffic to your web services based on the path entered.
The kubernetes.io/ingress.global-static-ip-name
annotation allows you to specify a named reserved ip-address that the Ingress resource will use when creating the Google Cloud Global HTTP(S) load balancer for the Ingress resource.
When you deploy this manifest, Kubernetes creates an ingress resource on your cluster. The ingress controller running in your cluster is responsible for creating an HTTP(S) load balancer to route all external HTTP traffic (on port 80) to the web NodePort service and the LoadBalancer service that you exposed.
In the Google Cloud Console Navigate to Networking > Network Services > Load Balancing. You should now also see a HTTP(S) Load Balancer listed.
Click the name to open the details page. The details should show that it is a global HTTP(S) load balancer using the static IP address you called global-ingress
when you reserved it earlier.
Click Check my progress to verify the objective.
Partial output:
Repeat the command every few minutes to check if the Ingress resource has finished initializing. When the Google Cloud global HTTP(S) load balancer has been created and initialized the command will report the external ip-address which will match the global static ip-address you reserved earlier that you called global-ingress
.
[external_IP]
with the Ingress resource's external IP address. Be sure to include the /v1 in the URL path:Example:
Output:
The v1 URL is configured in hello-ingress.yaml
to point to the hello-svc
NodePort service that directs traffic to the v1 application Pods.
[external_IP]
with the Ingress resource's external IP address. Be sure to include the /v2 in the URL path:The v2 URL is configured in hello-ingress.yaml
to point to the hello-lb-svc
LoadBalancer service that directs traffic to the v2 application Pods.
Example:
Output:
There are now two load balancers listed:
There is the initial regional load balancer for the hello-lb-svc
service. This has a UID style name and is configured to load balance TCP port 80 traffic to the cluster nodes.
The second was created for the Ingress object and is a full HTTP(S) load balancer that includes host and path rules that match the Ingress configuration. This will have hello-ingress
in its name.
hello-ingress
in the name.This will display the summary information about the protocols, ports, paths and backend services of the Google Cloud Global HTTP(S) load balancer created for your Ingress resource.
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:
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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one