
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 a Kubernetes cluster
/ 5
Create the monolith pod
/ 5
Create the healthy-monolith pod
/ 5
Create a secret, service, firewall rule and pod with label
/ 5
In this lab, you learn how to:
kubectl.
You use Kubernetes Engine and its Kubernetes API to deploy, manage, and upgrade applications. You use an example application called "app" to complete the labs.
Note: App is hosted on GitHub. It's a 12-Factor application with the following Docker images:
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.
Make sure the following APIs are enabled in Cloud Platform Console:
Expand the Navigation menu (), then click APIs & services.
Scroll down and confirm that your APIs are enabled.
If an API is missing, click ENABLE APIS AND SERVICES at the top, search for the API by name, and enable it for your project.
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.
Output:
Example output:
Output:
Example output:
You'll see the following structure.
|
|
|
|
|
|
|
|
|
|
|
|
Now that you have the code, it's time to try Kubernetes.
bootcamp
that runs 5 nodes:The scopes
argument provides access to project hosting and Google Cloud Storage APIs that you'll use later.
Click Check my progress to verify the objective.
kubectl version
command:gcloud container clusters create
command automatically authenticated kubectl
for you.
kubectl cluster-info
to find out more about the cluster:Kubernetes comes with auto-completion. You can use the kubectl completion command and the built-in source
command to set this up.
Press Tab to display a list of available commands.
Try the following examples:
You can also complete a partial command:
This feature makes using kubectl
even easier.
The easiest way to get started with Kubernetes is to use the kubectl create deployment
command.
kubectl create deployment
to launch a single instance of the nginx container:Note: In Kubernetes, all containers run in pods. And in this command, Kubernetes created what is called a deployment
behind the scenes, and runs a single pod with the nginx container in it.
kubectl get pods
command to view the pod running the nginx container:kubectl expose
command to expose the nginx container outside Kubernetes:service
and an external load balancer with a public IP address attached to it (you will learn about services later). The IP address remains the same for the life of the service. Any client who hits that public IP address (for example an end user or another container) is routed to pods behind the service. In this case, that would be the nginx pod.
kubectl get
command to view the new service:You'll see an external IP that you can use to test and contact the nginx container remotely.
ExternalIP
field is populated for your service. This is normal—just re-run the kubectl get services
command every few seconds until the field is populated.
kubectl scale
command to scale up the number of backend applications (pods) running on your service using.This is useful when you want to increase workload for a web application that is becoming more popular:
kubectl get services
command again to confirm that your external IP address has not changed:curl
command to test your demo application:Kubernetes supports an easy-to-use workflow out of the box using the kubectl run
, expose
, and scale
commands.
Now that you've seen a quick tour of Kubernetes, it's time to dive into each of the components and abstractions.
Investigate pods in more detail.
Pods can be created using pod configuration files.
kubectl explain
command:kubectl explain
will be one of the most common commands you use. Note how you used it above to investigate an API object and how you will use it below to check on various properties of API objects.monolith
). You pass a few arguments to the container when it starts up and open port 80 for HTTP traffic.
kubectl explain
command with the .spec
option to view more information about API objects. This example inspects containers.Explore the rest of the API before you continue.
monolith
pod using kubectl create
:Click Check my progress to verify the objective.
kubectl get pods
command to list all pods running in the default namespace:kubectl describe
command to get more information about the monolith
pod:You'll see a lot of the information about the monolith
pod, including the pod IP address and the event log. This information will be useful when troubleshooting.
As you can see, Kubernetes makes it easy to create pods by describing them in configuration files and to view information about them when they are running. At this point, you can create all the pods your deployment requires!
Pods are allocated a private IP address by default that cannot be reached outside of the cluster. Use the kubectl port-forward
command to map a local port to a port inside the monolith
pod.
Use two terminals: one to run the kubectl port-forward
command, and the other to issue curl
commands.
+
button in Cloud Shell to open a new terminal.curl
command:You get a friendly "Hello" back from the container.
You should get an error.
monolith
:password
to sign in.curl
.
At the login prompt, enter the password as password
to sign in.
Access the secure endpoint again, and this time include the auth token:
kubectl logs
command to view logs for the monolith
pod:Open another terminal and use the -f
flag to get a stream of logs in real-time!
+
button in Cloud Shell and run the following command:curl
in terminal 1 to interact with monolith
. And you see logs update in terminal 3:kubectl exec
command to run an interactive shell inside the monolith
pod. This can be useful when you want to troubleshoot from within a container:ping
command:As you can see, interacting with pods is as easy as using the kubectl
command. If you need to test a container remotely or get a login shell, Kubernetes provides everything you need to start.
kubectl port-forward
and kubectl logs
in terminal 2 and 3, press Ctrl+C
.Kubernetes supports monitoring applications in the form of readiness and liveness probes. Health checks can be performed on each container in a pod. Readiness probes indicate when a pod is "ready" to serve traffic. Liveness probes indicate whether a container is "alive."
If a liveness probe fails multiple times, the container is restarted. Liveness probes that continue to fail cause a pod to enter a crash loop. If a readiness check fails, the container is marked as not ready and is removed from any load balancers.
In this lab, you deploy a new pod named healthy-monolith
, which is largely based on the monolith
pod with the addition of readiness and liveness probes.
In this lab, you learn how to:
healthy-monolith
pod configuration file.healthy-monolith
pod using kubectl
.Click Check my progress to verify the objective.
kubectl describe
command to view details for the healthy-monolith pod:See how Kubernetes responds to failed readiness probes. The monolith
container supports the ability to force failures of its readiness and liveness probes. This enables you to simulate failures for the healthy-monolith
pod.
kubectl port-forward
command in terminal 2 to forward a local port to the health port of the healthy-monolit
h pod:monolith
container readiness probe to fail. Use the curl
command in terminal 1 to toggle the readiness probe status. Note that this command does not show any output:healthy-monolith
pod using the kubectl get
pods -w
command:0/1
ready containers. Use the kubectl describe
command to get more details about the failing readiness probe:healthy-monolith
pod report details about failing readiness probes.To force the monolith
container readiness probe to pass, toggle the readiness probe status by using the curl
command:
healthy-monolith
pod using the kubectl get pods
command:kubectl
proxy (i.e port-forward
) command.Building on what you learned in the previous tutorial, use the kubectl port-forward
and curl
commands to force the monolith
container liveness probe to fail. Observe how Kubernetes responds to failing liveness probes.
kubectl port-forward
command to forward a local port to the health port of the healthy-monolith
pod in terminal 2.monolith
container readiness probe to pass, toggle the readiness probe status by using the curl
command in another terminal:healthy-monolith
pod using the kubectl get pods -w
command:When a liveness probe fails, the container is restarted. Once restarted, the healthy-monolith
pod should return to a healthy state. Press Ctrl+C
to exit that command when the pod restarts. Note the restart count.
Use the kubectl describe
command to get more details about the failing liveness probe. You can see the related events for when the liveness probe failed and the pod was restarted:
Ctrl+C
in terminal 2 to close the kubectl proxy
command.Next steps:
Before creating your services, create a secure pod with an nginx server called secure-monolith
that can handle HTTPS traffic.
Create two volumes that the secure pod will use to bring in (or consume) data.
The first volume of type secret
stores TLS cert files for your nginx server.
tls/
and stores them in a secret
called tls-certs
.
ConfigMap
to hold nginx's configuration file:proxy.conf
file to the cluster and calls the ConfigMap nginx-proxy-conf
.
proxy.conf
file that nginx will use:The file specifies that SSL is ON and specifies the location of cert files in the container file system.
secret
volume, so you need to mount the volume to the container's file system.secure-monolith
pod configuration file:volumes
, the pod attaches the two volumes you created. And under volumeMounts
, it mounts the tls-certs
volume to the container's file system so nginx can consume the data.secure-monolith
pod with its configuration data:Now that you have a secure pod, expose the secure-monolith
pod externally using a Kubernetes service.
The file contains:
selector
that finds and exposes pods with labels app=monolith
and secure=enabled
targetPort
and nodePort
that forward external traffic from port 31000 to nginx on port 443.kubectl create
command to create the monolith service from the monolith service configuration file:type: NodePort
in the Service's yaml file means that it uses a port on each cluster node to expose the service. This means that it's possible to have port collisions if another app tries to bind to port 31000 on one of your servers.
Normally, Kubernetes handles this port assignment for you. In this lab, you chose one so that it's easier to configure health checks later.
gcloud compute firewall-rules
command to allow traffic to the monolith service on the exposed nodeport:Now that everything is set up, you should be able to test the secure-monolith
service from outside the cluster without using port forwarding.
Note: It's time for a quick knowledge check. Use the following commands to answer the questions below.
kubectl get services monolith
kubectl describe services monolith
Questions:
Currently the monolith service does not have any endpoints. One way to troubleshoot an issue like this is to use the kubectl get pods
command with a label query.
app=monolith
and secure=enabled
?kubectl label
command to add the missing secure=enabled
label to the secure-monolith
pod:Click Check my progress to verify the objective.
monolith
service:secure-monolith
is using a self-signed certificate:You learned about Kubernetes services and how pod endpoints are selected using labels. You also learned about Kubernetes volumes and how to configure applications using ConfigMaps and secrets.
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