Hands-On With Kubernetes + Google Cloud Platform
What is Kubernetes?
Kubernetes was originally created by Google, with version 1.0 launched in 2015. It was inspired by the company’s Borg data center management software.
Kubernetes automates the deployment, scaling, maintenance, scheduling and operation of multiple application containers across clusters of nodes. Containers run on top of a common shared operating system (OS) on host machines but are isolated from each other unless a user chooses to connect them.
Kubernetes is mainly used by application developers and IT system administrators, including DevOps engineers, in organizations that deploy containers.
Architecture
Creating a Kubernetes Cluster with Google Kubernetes Engine (GKE) + Deploy Apps on it
prerequisites
- You already have a Google Account and have access to Google Cloud Console (https://console.cloud.google.com)
- Billing account enabled that can be used in this project
Step 1 — Create a Google Cloud Project
In here I create google cloud project as the below image.
After it created a project it will be showing as follow.
Step 2: Create a Kubernetes Cluster
Now we created the new project, next we need to create a Kubernetes cluster as follows.
After some time your GKE cluster is ready to use !!
Step 3: Deploy an App in your Cluster
Here I used 2 node.js applications to according to the given scenario. Those are api_service and data_service.
API Service: expose 2 API endpoints as “/codeToState” and “/stateToCode” , pass parameters as URL parameters.
API endpoints
- http://host/codeToState?code=XX
- http://host/stateToCode?state=XXXX
Data Service: read data from JSON files and provide relevant data requested by APIService.
Here is the repository link: https://github.com/Tharinduyasarathna27/nodeapp
This is the file structure of built apps for the given scenario.
Also below I attach images of my api-service rest API endpoints change before push it to docker-hub.
We need to create 2 docker images and push them to Docker Hub.
After that, we need to run our GKE cluster on the cloud shell.
Then we need to run following commands to Pull the image from the Repository and create a Container on the Cluster.
$ kubectl run api --image=docker.io/tharindu27/api_service:latest --port=3100 --replicas=2$ kubectl run data --image=docker.io/tharindu27/data_service:latest --port=3101 --replicas=2
When the create those things we need to expose the Kubernetes Deployment through a Load Balancer.
$ kubectl expose deployment api --type=LoadBalancer --port=80 --target-port=3100$ kubectl expose deployment data --type=ClusterIP --port=80 --target-port=3101
And now you know the external IP address of your container.
node-app api_service is now exposed on http://35.200.153.222/ (http://35.200.153.222/codeToState?code=XX or http://35.200.153.222/stateToCode?state=XXXX ) through a Kubernetes Load Balancer!
And that’s it !! Happy Coding!