In this lab, you deploy a simple Windows app to Docker running on a Compute Engine instance. You will then push the same app into Google Container Registry and deploy it to Google Kubernetes Engine.
Objectives
In this lab, you learn how to perform the following tasks:
Create a simple Windows app.
Containerize the app using Docker.
Create your Kubernetes cluster on Kubernetes Engine.
Deploy your app to a pod.
Allow external traffic to your pod.
Task 1: Sign in to the Cloud Console
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.
Task 2: Enable Google Container Registry API
On the Google Cloud menu, click Activate Cloud Shell () icon then click Continue.
Make sure the Google Container Registry API is enabled, by running the following command:
On the Navigation menu (), click Compute Engine > VM instances.
Click the Drop down arrow icon next to RDP button and select Set Windows password.
Copy and save the Username value and click SET.
Copy and save the New Windows Password and click CLOSE.
Use credentials created in previous steps.
Once inside the Windows VM, you'll notice that it's a bare-minimum OS with minimal UI.
In the Windows command prompt (C:\Users\gcpstagingXXXXX_stud>), run the following to see the images that are installed by default:
docker images
(Output):
REPOSITORY TAG IMAGE ID
mcr.microsoft.com/windows/servercore ltsc2019 29a2c2cb7e4d
Task 4: Create a Windows container app
For the app inside the Windows container, use an IIS Web Server. IIS has an image for Windows Server 2019. You can use the image as is and it will serve the default IIS page, but for this lab, do something more interesting and have IIS serve a page you define.
Create a folder called my-windows-app and enter into the directory:
mkdir my-windows-app
cd my-windows-app
Create folder named content:
mkdir content
Create a file named index.html in the content folder:
Save the index.html. This is the page IIS will serve.
Task 5: Build Docker image
Create a Dockerfile for the Docker image.
call > Dockerfile
Edit the dockerfile:
notepad Dockerfile
Add the following contents in the Dockerfile:
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*
WORKDIR /inetpub/wwwroot
COPY content/ .
Save the Dockerfile.
Build the Docker image and tag it with Google Container Registry (GCR) and your project id. This will be useful when we push the image to GCR later (replace [PROJECT_ID] with your Qwiklabs project id):
Once the Docker image is built, you can see it along with its IIS dependency:
docker images
Sample output:
REPOSITORY TAG
gcr.io/[PROJECT_ID]/iis-site-windows latest
mcr.microsoft.com/windows/servercore/iis windowsservercore-ltsc2019
mcr.microsoft.com/windows/servercore ltsc2019
Run the following command to run the Windows container from your VM instance:
docker run -d -p 80:80 gcr.io/[PROJECT_ID]/iis-site-windows
Return to the Cloud Console. On the Navigation menu (), click Compute Engine > VM instances.
Open a browser window enter the External IP of the Compute Engine instance to see the app:
Task 6: Push container image to Google Container Registry
Configure Docker to point to Google Container Registry (GCR):
gcloud auth configure-docker
When prompted enter Y.
The output should look like this
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
After update, the following will be written to your Docker config file
located at [C:\Users\student_01_9786da300\.docker\config.json]:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
Do you want to continue (Y/n)? Y
Docker configuration file updated.
Push the image to Container Repository. Remember to replace [PROJECT_ID] with your Qwiklabs project id.
docker push gcr.io/[PROJECT_ID]/iis-site-windows
If you return to the Cloud Console and go Container Repository in the Navigation Menu you can see the image
Click Check my progress to verify the objective.
Push Container image to Container Registry
Task 7: Start a Kubernetes Engine cluster
In Cloud Console, on the Google Cloud menu, click Activate Cloud Shell () icon then click Continue.
Run the following command to set your environment variables for the project and zones and to set them as default:
export PROJECT_ID=[PROJECT_ID]
gcloud config set project ${PROJECT_ID}
export ZONE=us-central1-a
gcloud config set compute/zone ${ZONE}
Start a Kubernetes cluster managed by Kubernetes Engine. Name the cluster win-cluster and configure it to run 2 nodes:
It takes several minutes to create a cluster as Kubernetes Engine provisions virtual machines for you.
Eventually, the cluster should be created.
Example output
Creating cluster win-cluster in us-central1-a... Cluster is being health-checked (master is healthy)...done.
Created [https://container.googleapis.com/v1/projects/qwiklabs-gcp-03-52c197b33d26/zones/us-central1-a/clusters/win-cluster].
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/win-cluster?project=qwiklabs-gcp-03-52c197b33d26
kubeconfig entry generated for win-cluster.
NAME: win-cluster
LOCATION: us-central1-a
MASTER_VERSION: 1.22.11-gke.400
MASTER_IP: 34.123.19.209
MACHINE_TYPE: e2-medium
NODE_VERSION: 1.22.11-gke.400
NUM_NODES: 2
STATUS: RUNNING
After the cluster is created, check your installed version of Kubernetes using the kubectl version command:
kubectl version
The gcloud container clusters create command automatically authenticated kubectl for you.
View your running nodes in the Cloud Console. On the Navigation menu (), click Compute Engine > VM Instances.
Your Kubernetes cluster is now ready for use.
Click Check my progress to verify the objective.
Start a Kubernetes Engine cluster
Task 8: Add Windows Node to cluster
Once we have the basic GKE cluster, we can go ahead and add a Windows pool for Windows nodes to it:
Before using the cluster, wait for several seconds until windows.config.common-webhooks.networking.gke.io is created. This webhook adds scheduling tolerations to Pods created with the kubernetes.io/os: windows (or beta.kubernetes.io/os: windows) node selector to ensure they are allowed to run on Windows Server nodes. It also validates the Pod to ensure that it only uses features supported on Windows.
Press Ctrl+O, and then press Enter to save your edited file.
Press Ctrl+X to exit the nano text editor.
Create a deployment for the cluster with the following command:
kubectl apply -f iis-site-windows.yaml
Check the deployment with the following command:
kubectl get deployment,pods
After a few minutes, you should see the deployment created and pods running:
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/iis-site-windows 2/2 2 2 3m4s
NAME READY STATUS RESTARTS AGE
pod/iis-site-windows-5b6dfdf64b-k5b6r 1/1 Running 0 3m4s
pod/iis-site-windows-5b6dfdf64b-msr9s 1/1 Running 0
Task 11: Create a Kubernetes Service
To make pods accessible to the outside world, we need to create a Kubernetes service with LoadBalancer type:
In a few minutes, you should see a new service with an external IP:
kubectl get service
You should see an output like this:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
iis-site-windows LoadBalancer 10.107.11.34 104.155.45.254 80:30035/TCP
Open a browser window and go to the external IP of the load balancer, you will see the app:
Click Check my progress to verify the objective.
Create a Kubernetes Service
Congratulations!
You have successfully configured and deployed a GKE cluster running a Windows Server workload.
In this lab, you learned how to perform the following tasks:
Create a simple Windows app.
Containerize the app using Docker.
Create your Kubernetes cluster on Kubernetes Engine.
Deploy your app to a pod.
Allow external traffic to your pod.
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.
Lab membuat project dan resource Google Cloud untuk jangka waktu tertentu
Lab memiliki batas waktu dan tidak memiliki fitur jeda. Jika lab diakhiri, Anda harus memulainya lagi dari awal.
Di kiri atas layar, klik Start lab untuk memulai
Gunakan penjelajahan rahasia
Salin Nama Pengguna dan Sandi yang diberikan untuk lab tersebut
Klik Open console dalam mode pribadi
Login ke Konsol
Login menggunakan kredensial lab Anda. Menggunakan kredensial lain mungkin menyebabkan error atau dikenai biaya.
Setujui persyaratan, dan lewati halaman resource pemulihan
Jangan klik End lab kecuali jika Anda sudah menyelesaikan lab atau ingin mengulanginya, karena tindakan ini akan menghapus pekerjaan Anda dan menghapus project
Konten ini tidak tersedia untuk saat ini
Kami akan memberi tahu Anda melalui email saat konten tersedia
Bagus!
Kami akan menghubungi Anda melalui email saat konten tersedia
Satu lab dalam satu waktu
Konfirmasi untuk mengakhiri semua lab yang ada dan memulai lab ini
Gunakan penjelajahan rahasia untuk menjalankan lab
Gunakan jendela Samaran atau browser pribadi untuk menjalankan lab ini. Langkah ini akan mencegah konflik antara akun pribadi Anda dan akun Siswa yang dapat menyebabkan tagihan ekstra pada akun pribadi Anda.
In this lab, you deploy a simple Windows app to Docker running on a Compute Engine instance. You will then push the same app into Google Container Registry and deploy it to Google Kubernetes Engine.