Deploying Application In Kubernetes

Hi Folks,

In my last blog, we have seen how to build a docker images and push it to Google container registry. In this blog i’m going to deploy same image on Kubernetes (K8s).

Kubernetes ( is an opensource project for automating deployment, scaling, and management of containerized applications.

Create a Cluster

To create a cluster, navigate to Kubernetes Engine > Kubernetes clusters > Create cluster OR use below command

gcloud container clusters create my-cluster-1 \
                --num-nodes 2 \
                --machine-type n1-standard-1 \
                --zone us-central1-a

From now on you’ll use the kubectl command line (already set up in your Cloud Shell environment).

Now setup the gcloud and kubectl credentials: to get gcloud credentials for the cluster that you created. Enter the zone and name of the cluster that you created.

gcloud container clusters get-credentials my-cluster-1 --zone us-central1-a

Create a Pod

A Kubernetes pod is a group of containers tied together for administration and networking purposes. It can contain single or multiple containers. A Pod can be created using kubectl run command

kubectl run vinapp-node --port=8999

It will create a deployment object i.e. vinapp-node. Deployments are used to create and scale Pods. to view the deployment use command

kubectl get deployments

To view Pod created by deployment use

kubectl get pods OR kubectl get pods -o wide

By default Pod is accessible by its internal IP within cluster. In order to expose vinapp-node to external world, we need to create a Kubernetes service with –type=LoadBalancer flag

kubectl expose deployment vinapp-node –type=”LoadBalancer”

Note here deployment getting exposed not the Pod directly. This will cause the resulting service to load balance traffic across all pods managed by the deployment.

To find the publicly-accessible IP address of the service, request kubectl to list all the cluster services:

kubectl get services

It will output two IP adddress, The CLUSTER-IP is the internal IP that is only visible inside your cloud virtual network; the EXTERNAL-IP is the external load-balanced IP.

Now you should able to access your application by using following URL


That’s All. Application running on kubernetes now !!!

Some useful commands:

kubectl describe pod <POD-UID>
kubectl get configmaps my-config -o yaml

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s