Cluster orchestration with Google Kubernetes Engine

List of advanced cluster management features that Google Cloud provides:

Load balancing for Compute Engine instances
Node pools to designate subsets of nodes within a cluster for additional flexibility
Automatic scaling of your cluster's node instance count
Automatic upgrades for your cluster's node software
Node auto-repair to maintain node health and availability
Logging and Monitoring with Cloud Monitoring for visibility into your cluster

Activate Cloud Shell

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. Cloud Shell provides command-line access to your Google Cloud resources.

Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to qwiklabs-gcp-02-40d87254d20c.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud auth list
Credentialed Accounts

ACTIVE: *
ACCOUNT: student-02-38f9112c459d@qwiklabs.net

To set the active account, run:
    $ gcloud config set account `ACCOUNT`

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud config list project
[core]
project = qwiklabs-gcp-02-40d87254d20c

Your active configuration is: [cloudshell-4461]
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Set a default compute zone

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud config set compute/region us-east4
Updated property [compute/region].
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Create a GKE cluster

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud container clusters create --machine-type=e2-medium --zone=us-east4-a lab-cluster
Default change: 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
Default change: During creation of nodepools or autoscaling configuration changes for cluster versions greater than 1.24.1-gke.800 a default location policy is applied. For Spot and PVM it defaults to ANY, and for all other VM kinds a BALANCED policy is used. To change the default values use the `--location-policy` flag.
Note: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
Creating cluster lab-cluster in us-east4-a... Cluster is being health-checked (master is healthy)...working..

After 2-3 minutes

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud container clusters create --machine-type=e2-medium --zone=us-east4-a lab-cluster
Default change: 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
Default change: During creation of nodepools or autoscaling configuration changes for cluster versions greater than 1.24.1-gke.800 a default location policy is applied. For Spot and PVM it defaults to ANY, and for all other VM kinds a BALANCED policy is used. To change the default values use the `--location-policy` flag.
Note: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s).
Creating cluster lab-cluster in us-east4-a... Cluster is being health-checked (master is healthy)...done.     
Created [https://container.googleapis.com/v1/projects/qwiklabs-gcp-02-40d87254d20c/zones/us-east4-a/clusters/lab-cluster].
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-east4-a/lab-cluster?project=qwiklabs-gcp-02-40d87254d20c
kubeconfig entry generated for lab-cluster.
NAME: lab-cluster
LOCATION: us-east4-a
MASTER_VERSION: 1.24.9-gke.3200
MASTER_IP: 35.245.25.171
MACHINE_TYPE: e2-medium
NODE_VERSION: 1.24.9-gke.3200
NUM_NODES: 3
STATUS: RUNNING
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Get authentication credentials for the cluster

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud container clusters get-credentials lab-cluster --zone=us-east4-a
Fetching cluster endpoint and auth data.
kubeconfig entry generated for lab-cluster.
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Let’s view the kubectl config:

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://35.245.25.171
  name: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
contexts:
- context:
    cluster: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
    user: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
  name: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
current-context: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
kind: Config
preferences: {}
users:
- name: gke_qwiklabs-gcp-02-40d87254d20c_us-east4-a_lab-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args: null
      command: gke-gcloud-auth-plugin
      env: null
      installHint: Install gke-gcloud-auth-plugin for use with kubectl by following
        https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
      interactiveMode: IfAvailable
      provideClusterInfo: true
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Deploy an application to the cluster

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

deployment.apps/hello-server created
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ kubectl get all
NAME                                READY   STATUS    RESTARTS   AGE
pod/hello-server-5597d96dd4-8q62q   1/1     Running   0          58s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.68.0.1    <none>        443/TCP   7m44s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-server   1/1     1            1           60s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-server-5597d96dd4   1         1         1       60s
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ kubectl expose deployment hello-server --type=LoadBalancer --port=8080
service/hello-server exposed
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Check that the service is created and an External IP is assigned

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ kubectl get all
NAME                                READY   STATUS    RESTARTS   AGE
pod/hello-server-5597d96dd4-8q62q   1/1     Running   0          3m14s

NAME                   TYPE           CLUSTER-IP    EXTERNAL-IP      PORT(S)          AGE
service/hello-server   LoadBalancer   10.68.1.240   35.236.222.243   8080:32166/TCP   61s
service/kubernetes     ClusterIP      10.68.0.1     <none>           443/TCP          10m

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/hello-server   1/1     1            1           3m15s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/hello-server-5597d96dd4   1         1         1       3m15s
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Verify the service

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ curl http://35.236.222.243:8080/
Hello, world!
Version: 1.0.0
Hostname: hello-server-5597d96dd4-8q62q
student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$

Delete the cluster

student_02_38f9112c459d@cloudshell:~ (qwiklabs-gcp-02-40d87254d20c)$ gcloud container clusters delete lab-cluster --zone=us-east4-a
The following clusters will be deleted.
 - [lab-cluster] in [us-east4-a]

Do you want to continue (Y/n)?  y

Deleting cluster lab-cluster...working.  
Deleting cluster lab-cluster...done.     
Deleted [https://container.googleapis.com/v1/projects/qwiklabs-gcp-02-40d87254d20c/zones/us-east4-a/clusters/lab-cluster].

You have just deployed a containerized application to Kubernetes Engine!

Tags:

Categories:

Updated:

Back to Top ↑