Get Started with Google Kubernetes Engine GKE

Prajwol KC
3 min readNov 13, 2020

Let's get to know what we are doing here.

Confirm that needed APIs are enabled.

  1. Make a note of the name of GCP project. This value is shown in the top bar of the Google Cloud Platform Console. It will be of the form qwiklabs-gcp- followed by hexadecimal numbers.
  2. In the GCP Console, on the Navigation menu, click APIs & Services.
  3. Scroll down in the list of enabled APIs, and confirm that both of these APIs are enabled:
  • Kubernetes Engine API
  • Container Registry API

Start a Kubernetes Engine cluster

  1. In GCP console, on the top right toolbar, click the Open Cloud Shell button.
  2. Click Continue.
  3. For convenience, assign you to into an environment variable called MY_ZONE. At the Cloud Shell prompt, type this partial command:
export MY_ZONE=us-central1-a

4. Start a Kubernetes cluster managed by Kubernetes Engine. Name the cluster webfrontend and configure it to run 2 nodes:

gcloud container clusters create webfrontend --zone $MY_ZONE --num-nodes 2

5. It takes several minutes to create a cluster as Kubernetes Engine provisions virtual machines.

6. After the cluster is created, check installed version of Kubernetes using the kubectl version command:

kubectl version

7. The gcloud container clusters create command automatically authenticated kubectl.

8. View running nodes in the GCP Console. On the Navigation menu, click Compute Engine > VM Instances. Kubernetes cluster is now ready for use

Run and deploy a container

kubectl create deploy nginx --image=nginx:1.17.10
  1. In Kubernetes, all containers run in pods. This use of the kubectl create command caused Kubernetes to create a deployment consisting of a single pod containing the nginx container. A Kubernetes deployment keeps a given number of pods up and running even in the event of failures among the nodes on which they run. In this command, we launched the default number of pods, which is 1.
  2. View the pod running the nginx container:
kubectl get podskubectl expose deployment nginx --port 80 --type LoadBalancer
  1. Kubernetes created a service and an external load balancer with a public IP address attached to it. The IP address remains the same for the life of the service. Any network traffic to that public IP address is routed to pods behind the service: in this case, the nginx pod.
  2. View the new service: You can use the displayed external IP address to test and contact the nginx container remotely.
kubectl get services

It may take a few seconds before the External-IP field is populated for service. This is normal. Just re-run the kubectl get services command every few seconds until the field is populated.

  1. Open a new web browser tab and paste your cluster’s external IP address into the address bar. The default home page of the Nginx browser is displayed.
  2. Scale up the number of pods running on your service:
    kubectl scale deployment nginx --replicas 3
  3. Scaling up a deployment is useful when you want to increase available resources for an application that is becoming more popular.
  4. Confirm that Kubernetes has updated the number of pods:
    kubectl get pods
  5. Confirm that your external IP address has not changed:
    kubectl get services
  6. Return to the web browser tab in which we viewed your cluster’s external IP address. Refresh the page to confirm that the nginx web server is still responding.

Originally published at https://prajwol-kc.com.np on November 13, 2020.

--

--