GCP Certification — let’s sail together. About Docker, Kubernetes and Google Kubernetes Engine

Chaskarshailesh
Javarevisited
Published in
5 min readNov 22, 2021

First Introduction to Docker

Docker is an open platform for developing, shipping, and running applications. With Docker, you can separate your applications from your infrastructure and treat your infrastructure like a managed application.Docker containers can be directly used in Kubernetes, which allows them to be run in the Kubernetes Engine with ease.

One of the best lab to get hands on with Docker— Introduction to Docker (Refer below for detail steps)

Second about Kubernetes

Kubernetes is an open source project which can run on many different environments, from laptops to high-availability multi-node clusters; from public clouds to on-premise deployments; from virtual machines to bare metal.

One of the best lab to get hands on with Kubernetes — Introduction to Kubernetes (Refer below for detail steps)

I recommend watching below two amazing videos by Anshul Tiwari :

  1. Kubernetes crash course: In less than 15 minutes
  2. Lets understand containers | 5 simple steps to create a docker container

Finally about Google Kubernetes Engine

Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure.

Google Kubernetes Engine (GKE) clusters are powered by the Kubernetes open source cluster management system.

Kubernetes provides the mechanisms through which you interact with your container cluster.

One of the best lab to get hands on with GKE — Kubernetes Engine: Qwik Start (Refer below for detail steps)

I recommend watching below playlist of 3 amazing videos by GK : Google Kubernetes Engine — YouTube

Introduction to Docker Lab Steps:-

In this lab, you will learn:-
• Ran containers based on public images from Docker Hub.
• Build your own container image and push it to Google Container Registry.
• Learned ways to debug running containers.
Ran containers based on images pulled from Google Container Registry.

Step 1 : Run hello World Container
Step 2 : Hello World image doesn’t exist on the VM hence it pulls it from Docker Hub — a Public Repository
Step 3 : When you run hello world container this time it doesn’t give message about “Unable to find image locally — Pulling from library/hello-world “, since it already exists.
Step 4 : Build a new node.js app : my-app (including Docker File and an app js file)
Step 5 : Build Docker Image and run my-app v1 container
Step 6 : Another way to run my-app v1 container in background with -d flag
Step 7 : Build version 2 of node.js : my-app with a different message. Then build docker image for my-app v2
Step 8 : Add on info : Debug container logs using docker logs -f <container id>
Step 9 : Add on info : Start an interactive Bash session inside the running container. You can use docker exec to do this — docker exec -it [container_id] bash
Step 10 : Add on info : Examine a container’s metadata in Docker by using Docker inspect : docker inspect [container_id]
Step 11 : Add on info :To inspect specific fields from the returned JSON use — format . For example:
docker inspect — format=’{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ [container_id]
Step 12 : Now time to move to cloud from VM, Publish image to Google container registry for which the format is :

[hostname]/[project-id]/[image]:[tag].

For google cloud registry :-
[hostname]= gcr.io
[project-id]= your project’s ID
[image]= your image name
[tag]= any string tag of your choice. If unspecified, it defaults to “latest”.

Step 13 : Remove all containers and clear existing images on VM so that you have only one container run from the Cloud image.
Step 14 : Pull image from Cloud and run container which prints “Hello Cloud”

Introduction to Kubernetes Lab Steps:

In this lab, you will learn:-
• How to build, run, and debug Docker containers.
• How to pull Docker images from Docker Hub and Google Container Registry.
• How to push Docker images to Google Container Registry.

Step 1 : Build a new server.js app : my-node (including server js file)
Step 2 : Use the built-in Web preview feature of Cloud Shell to access your app.
Step 3 : Build Docker Image for my-node v1 and run my-node v1 container
Step 4 : Access my-node app on port 8080 and then stop the container
Step 5 : Now time to move to cloud from VM, Publish image to Google container registry for which the format is :
[hostname]/[project-id]/[image]:[tag].
For google cloud registry :-
[hostname]= gcr.io
[project-id]= your project’s ID
[image]= your image name
[tag]= any string tag of your choice. If unspecified, it defaults to “latest”.
Validate you can see the image via Cloud Console under Navigation menu > Container Registry.
Step 6: Create with standard N1 machine and 2 nodes from Google Console via Kubernetes Engine > Kubernetes clusters > Create cluster.
Step 7 : Deploy the container image via Kubernetes Engine > Workloads
Step 8 : Expose the Deployment via Load Balancer via external IP on port 8080 — this can also be done from google cloud console
Step 9 : You should now be able to reach the service by pointing your browser to this address: http://<EXTERNAL_IP>:8080 — “Hello World” should be the message on screen
Step 10 : Scale up service in HOT MODE — no need to stop or redeploy your workload just scale up this is one of the powerful features offered by Kubernetes. Validate the scaled up nodes via deployments and pods count.
Step 9 : Roll out an upgrade to your service — another feature which allows deployment updates in HOT MODE without impacting users.
This an be done by changing image label for the container by editing existing hello-node deployment
Step 10 : You should now be able to reach the service by pointing your browser to this address: http://<EXTERNAL_IP>:8080 — “Hello Kubernetes World” should be the message on screen

Kubernetes Engine Qwik Start Lab Steps:

In this lab, you will learn:-

• How to Create Google Kubernetes Cluster
• Get Credentials to access Google Kubernetes Cluster
• How to deploy application to Google Kubernetes Cluster
• Deleting the Google Kubernetes Cluster

Step 1 : Set Default Zone for the lab (This is important)
If you set the default region it may create 3 nodes in each zone. If a region, for example uscentral as 3 zones, it will create 3*3–9 nodes.
This may block your account as its not needed to create nodes across diff zone in a region.
Step 2 : Create a GKE cluster : 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.
Step 3 : After creating your cluster, you need authentication credentials to interact with it.
gcloud container clusters get-credentials mycluster
Step 4 : create a new Deployment hello-server from the hello-app container image. This is the docker image to be deployed as a container on to K8s Cluster.
Step 5 : Finally Load balancing concept to expose hello application via a service to the outside world.

Way to go…..let’s sail together.

--

--

Chaskarshailesh
Javarevisited

I am a Site Reliability Engineer aspirant Cloud Solutions Architect. Further exploring the horizon into MLOps