Quantcast
Channel: Kumar Chinnakali – dataottam
Viewing all articles
Browse latest Browse all 65

Step By Steps for deploying an Hello World, APP on Google Cloud Platform Container using Docker & Kubernetes

$
0
0

Step By Steps for deploying an Hello World, APP on Google Cloud Platform Container using Docker & Kubernetes !

The name Kubernetes originates from Greek, meaning helmsman or pilot, and is the root of governor and cybernetic. K8S is an abbreviation derived by replacing the 8 letters “ubernete” with “8”.

Kubernetes is an open-source platform for automating deployment, scaling, and operations of application containers across clusters of hosts, providing container-centric infrastructure.

Kubernetes is not a mere orchestration system. In fact, it eliminates the need for orchestration. The technical definition of orchestration is execution of a defined workflow: first do A, then B, then C. In contrast, Kubernetes is comprised of a set of independent, composable control processes that continuously drive the current state towards the provided desired state. It shouldn’t matter how you get from A to C. Centralized control is also not required; the approach is more akin to choreography.

Step by Step packaging and deployment of application:

Step 1: Build the container image

Google Container Engine accepts Docker images as the application deployment format.

We have created an application and a Dockerfile. We are cloning it from github: https://github.com/kamakshig20/Kubernetes-Test/tree/master/sampleApp

Build a project and Open cloud shell in google cloud console:

1

git clone https://github.com/kamakshig20/Kubernetes-Test

2

 The application is a Node.js server application that responds to all requests with the message “Hello There, Have a Great Day! \n by Digital Foundry!” on port 8080. The repository also contains the Dockerfile which contains the instructions to build a container image of this application.

docker build -t gcr.io/kuber-175409/hello:v1 .

This command builds the container image of this application and tags it for uploading.

kuber-175409 is the Project id.

3

docker images

To verify that the image is built:

4

Step 2: Upload the container image

Next step is to upload your container image to a container registry

gcloud docker — push gcr.io/kuber-175409/hello:v1

5

Step 3: Run your container locally

To test your container image using your local Docker engine

docker run –rm -p 8080:8080 gcr.io/kuber-175409/hello:v1

6

Click “Web preview” on the top left to see your application running in a browser tab.

7

8

Shut down the container by pressing Ctrl+C in the tab where docker run command is running.

Step 4: Create your container cluster

Create a container cluster to run the container image. A cluster consists of a pool of compute instances running Kubernetes.

gcloud container clusters create mykubclus –zone us-central1-b

9

We have created a container cluster named mykubclus with default 3 nodes.

Step 5: Deploy your application

To deploy and manage applications on a Container Engine cluster, we communicate with the Kubernetes cluster management system by using the kubectl command-line tool.

Kubernetes represents applications as Pods, which are units that represent a container (or group of tightly-coupled containers). The Pod is the smallest deployable unit in Kubernetes. Here each Pod contains only our Node.js container image.

 kubectl run hello-from-df –image=gcr.io/kuber-175409/hello:v1 –port 8080

10

This creates a single Pod listening on port 8080. The kubectl run command causes Kubernetes to create a Deployment resource on cluster.

To view the Pod that got created by the Deployment:

kubectl get pods

11

Step 6: Expose application

The containers you run on Container Engine are not accessible from the internet, since they do not have external IP addresses. We expose the application to traffic from the internet by using the kubectl expose command.

kubectl expose deployment hello-from-df –type=LoadBalancer –port 8080

12

The kubectl expose command causes Kubernetes to create a Service resource, which provides networking and IP support to your application’s Pods. Container Engine creates an external IP and a Load Balancer for application.

kubectl get service

13

From here we determine the external IP address for application, copy the IP address and add the port number.

Point browser to this URL (e.g. http://35.193.64.66:8080/) to access the application.

Deployer: Kamakshi Gupta


Viewing all articles
Browse latest Browse all 65

Trending Articles