Now that you have a basic understanding of Kubernetes, you will learn how to deploy a containerized application with GKE in less than 30 minutes. Follow the steps below to set up your lab environment.
Task 1: Set a default compute zone
Your compute zone is an approximate regional location in which your clusters and their resources live. For example, us-central1-a is a zone in the us-central1 region.
To set your default compute zone to us-central1-a, start a new session in Cloud Shell, and run the following command:
Your active configuration is: [cloudshell-18528]
student_03_ade82501e04b@cloudshell:~ (qwiklabs-gcp-00-45d397b5dba5)$ gcloud config set compute/zone us-central1-a
Updated property [compute/zone].
ERROR: (gcloud.config.set) Your current active account [ACCOUNT] does not have any valid credentials
WARNING: Starting in January 2021, clusters will use the Regular release channel by default when `--cluster-version`, `--release-channel`, `--no-enable-autoupgrade`, and `--no-enable-autorepair` flags are not specified.
WARNING: Currently VPC-native is the default mode during cluster creation for versions greater than 1.21.0-gke.1500. To create advanced routes based clusters, please pass the `--no-enable-ip-alias` flag
WARNING: Starting with version 1.18, clusters will have shielded GKE nodes by default.
WARNING: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
WARNING: Starting with version 1.19, newly created clusters and node-pools will have COS_CONTAINERD as the default node image when no image type is specified.
Creating cluster my-kubecluster1 in us-central1-a...done.
Created [https://container.googleapis.com/v1/projects/qwiklabs-gcp-00-45d397b5dba5/zones/us-central1-a/clusters/my-kubecluster1].
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1-a/my-kubecluster1?project=qwiklabs-gcp-00-45d397b5dba5
A cluster consists of at least one cluster master machine and multiple worker machines called nodes. Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster.
To create a cluster, run the following command, replacing [CLUSTER-NAME] with the name you choose for the cluster (for example:my-cluster).
gcloud container clusters create [CLUSTER-NAME]
Copied!
You can ignore any warnings in the output. It might take several minutes to finish creating the cluster.
Expected output (Do not copy):
NAME LOCATION ... NODE_VERSION NUM_NODES STATUS
my-cluster us-central1-a ... 1.16.13-gke.401 3 RUNNING
Task 3: Get authentication credentials for the cluster
After creating your cluster, you need authentication credentials to interact with it.
To authenticate the cluster, run the following command, replacing [CLUSTER-NAME] with the name of your cluster:
Fetching cluster endpoint and auth data.
kubeconfig entry generated for my-cluster.
Task 4: Deploy an application to the cluster
You can now deploy a containerized application to the cluster. For this lab, you'll run hello-app in your cluster.
GKE uses Kubernetes objects to create and manage your cluster's resources. Kubernetes provides the Deployment object for deploying stateless applications like web servers. Service objects define rules and load balancing for accessing your application from the internet.
To create a new Deploymenthello-server from the hello-app container image, run the following kubectl create command:
This Kubernetes command creates a Deployment object that represents hello-server. In this case, --image specifies a container image to deploy. The command pulls the example image from a Container Registry bucket. gcr.io/google-samples/hello-app:1.0 indicates the specific image version to pull. If a version is not specified, the latest version is used.
To create a Kubernetes Service, which is a Kubernetes resource that lets you expose your application to external traffic, run the following kubectl expose command:
--port specifies the port that the container exposes.
type="LoadBalancer" creates a Compute Engine load balancer for your container.
Expected output (Do not copy):
service/hello-server exposed
To inspect the hello-server Service, run kubectl get:
kubectl get service
Copied!
Expected output (Do not copy):
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-server loadBalancer 10.39.244.36 35.202.234.26 8080:31991/TCP 65s
kubernetes ClusterIP 10.39.240.1 <none> 433/TCP 5m13s
To view the application from your web browser, open a new tab and enter the following address, replacing [EXTERNAL IP] with the EXTERNAL-IP for hello-server.
http://[EXTERNAL-IP]:8080
Copied!
Expected output:
Task 5: Deleting the cluster
To delete the cluster, run the following command:
gcloud container clusters delete [CLUSTER-NAME]
Cocopy
When prompted, type Y to confirm.
List of commands used:
student_03_ade82501e04b@cloudshell:~ (qwiklabs-gcp-00-45d397b5dba5)$ history
No comments:
Post a Comment