Kubernetes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Md.

Noor Alam
+8801726217566

My friend works for an organization that provides Core Banking Applications and a few banks in
Bangladesh are their clients. It is a monolithic application, meaning the application is responsible not just
for a particular task, but can perform every step needed to complete a Banking operation.

This architectural design has the advantage that one person can manage the deployment process, but it
also has a lot of disadvantages.

The list includes –


1. For all the unique functionalities, technology stacks are restricted. However, each technology has
particular strength for example; Python is good for conduct data analysis and so on.
2. In what is becoming increasingly common, even though there have been no changes made to
the other modules, the entire application which includes the functionality for Deposit, General
Banking, Trade Finance, reporting, etc. must be deployed after a straightforward change relating
to Loan. And, same for Vice-Versa.
3. And many more.

He shared with me the challenges they are facing and to get over this point, I introduced him two things.

1. Microservice:

It is a process of breaking up a huge application into more manageable, independent modules or


applications. For Example,

For General Activities, GB Module application.


For Loans and Advances, Lending Module
For Trade Finance, TF Module
For Reporting, Report Module.

These applications are autonomous and connected. Additionally, the technology stack will be selected
based on business needs.

Excellent. Any modifications to any application can now be released independently. However,
dependency management has become a problem since technology stacks have been selected based on
whether one is a good fit.

2. Docker

Containerize the independent modules/ apps along with dependencies.

That’s it, and so far so good. As a result, many containers include multiple applications as well as their
dependencies.

But, new problems appear. How all these containers can be managed, who will do scaling, load balancing,
clustering and orchestration?

He asked me is there not any such ways to automate operational tasks of container management. And
to get him out of those difficulties, I advise him to use Kubernetes.
Kubernetes
Kubernetes is a container orchestration tool that helps with the deployment and management of
containers. Within Kubernetes, a container runs logically in a Pod, which can be represented as one
instance of a running service.

What is Pod, Deployment, Service, etc?

Pods are the smallest, most basic deployable objects in Kubernetes. A Pod represents a single instance
of a running process in your cluster. Pods contain one or more containers, such as Docker containers.
When a Pod runs multiple containers, the containers are managed as a single entity and share the Pod's
resources.

A deployment is responsible for keeping a Set of Pods Running.

A service is responsible for enabling network access to a set of pods.

In the subsequent article, I will show the installation to deploying an application to analyzing the
dashboard for Kubernetes.

Installation Procedure in Windows OS

Once Docker is installed, setting up the Kubernetes environment is not difficult. Download two
executable files, No-1: minikube-windows-amd64.exe and No-2: kubectl.exe

Rename the “minikube-windows-amd64.exe” to “minikube.exe”, copy and paste the both executables into
a suitable location and set the directory to “Environment Valuable”.

Environment Variable Setup Verifying Version.

Finished.
Therefore the environment is ready; let’s quickly jump on a Demo implementation. The scope of this
document limited to –
How Kubernetes pulls a container image (i.e. MySql) from Docker Hub and Deploy?
Analyzing the Kubernetes Dashboard.
Creating a Demo CRUD Application and deploy it By Kubernetes.

How Kubernetes pulls a container image – MySql in this case - from Docker Hub, and Deploy?

Goal: Take a MySql Database dockerized image from Docker Hub, deploy and expose so that other
applications in various pods can utilize it.

It is all about giving specific instructions in a YAML or JSON file to carry out certain operations.

Define a 'Persistent Volume Claim'(PVC) for MySql Storage, dynamically provisioned by


cluster.
Configure 'Deployment' of MySql Server.
Define a 'Service' To Expose MySql to Other Services.

1. The set of instructions to Defince the PVC (Persistent Volume Claim):

What is PersistentVolumeClaim refers to? A request for storage by a user.

The below lines instruct Kubernetes to request 1Gi storage having ReadWrite promission. Others are for a
few metadata, like name, labeling etc.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim # name of PVC essential for identifying the storage data
labels:
app: mysql
tier: database
spec:
accessModes:
- ReadWriteOnce #This specifies the mode of the claim that we are trying to create.
resources:
requests:
storage: 1Gi #This will tell Kubernetes about the amount of space we are trying to claim.

2. Configure 'Deployment' of MySql Server.


apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
labels:
app: mysql
tier: database
spec:
selector: # mysql Pod Should contain same labels
matchLabels:
app: mysql
tier: database
strategy:
type: Recreate
template:
metadata:
labels: # Must match 'Service' and 'Deployment' selectors
app: mysql
tier: database
spec:
containers:
- image: mysql:5.7 # Take this image from docker-hub
args:
- "--ignore-db-dir=lost+found"
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value : root
- name: MYSQL_DATABASE # Setting Database Name
value : testing

ports:
- containerPort: 3306
name: mysql
volumeMounts: # Mounting volume obtained from Persistent Volume Claim
- name: mysql-persistent-storage
mountPath: /var/lib/mysql #This is the path in the container on which the mounting will take place.
volumes:
- name: mysql-persistent-storage # Obtaining 'volume' from PVC
persistentVolumeClaim:
claimName: mysql-pv-claim

3. Define a 'Service' To Expose MySql to Other Services.


apiVersion: v1
kind: Service
metadata:
name: mysql # DNS name
labels:
app: mysql
tier: database
spec:
ports:
- port: 3306
targetPort: 3306
selector: # mysql Pod Should contain same labels
app: mysql
tier: database
clusterIP: None # We Use DNS, Thus Cluster IP is not relevant

So, the instructions are ready, let’s say all are saved into the file named “db-deployment.yaml”.

To execute, call; kubectl apply -f db-deployment.yaml

According to the command prompt, three things are created, No.1- persistentvolumeclaim/mysql-pv-
claim, No.2- deployment.apps/mysql, and No.3- service/mysql.

Let's check at the Kubernetes Dashboard to see what happened.


Kubernetes Dashboard:

The dashboard indicates that a pod has been created into which the MySql database is now running. The
dashboard has many options that allow you to see what is happening in the background.

Let's check to see if the database in the pod is working properly now.

So, it is verified the MySql instance is up and running.


Creating a Demo CRUD Application

A tiny spring-loaded application for inserting "Order," showing the entire list or a specific order. MySQL
database has been utilized for them.

Note: This MySQL instance is local, not the Containerized one we set up earlier.

Properties to Configuration for Local MySQL Database. Enpoints for perform CRUD Operations
spring: ++++++
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver @RestController
url: jdbc:mysql://localhost:3306/testing @RequestMapping("/orders")
username: root public class OrderController {
password: root
@Autowired
hikari: private OrderService service;
initialization-fail-timeout: 0
jpa: @PostMapping
database-platform: org.hibernate.dialect.MySQL5Dialect public Order addOrder(@RequestBody Order order){
generate-ddl: true return service.addOrder(order);
show-sql: true }
hibernate:
@GetMapping
ddl-auto: update public List<Order> getOrders(){
return service.getOrders();
}

@GetMapping("/{id}")
public Order getOrderById(@PathVariable int id){
return service.getOrderById(id);
}
}

The other implementation specifics have been omitted for brevity. Let's now begin the testing.

Submiting an Order: Viewing Details of an Order By ID:


localhost:8080/orders/submitorder localhost:8080/orders/getorder/3

The Spring Boot Application is therefore ready on our local system. Suppose the name is “springboot-
crud-k8s-example”.
Deploy it By Kubernetes.

So far, we are talking about two applications. No-1: MySql DB, and No-2: springboot-crud-k8s-example.

The first application was ready at Docker Hub, we just pulled its containerized image and deployed. And
the later one is ours. That’s the difference.

Now, we have to tell Kubernetes, don’t look at Docker Hub, and take the Docker image from Local
Machine. For this it needs to create a Docker image for “springboot-crud-k8s-example” application.

The Work steps are as follows.

Work Progress:
Spring Boot App; Status: Done.
Docker Image; Status: In progress.
Kubernetes Deployment; Status: In progress.

Creating Docker Image: for “springboot-crud-k8s-example” application, and deploy to Kubernetes.

Create a “Dockerfile”. It contains instructions on how to launch the program, where to find the jar file,
how to expose the application at port 8080, and which dependencies (i.e. JDK 8) to be downloaded from
Docker Hub.

However, we must switch the DB connectivity from the local DB schema to the Containerized MySQL
database before building the Docker image.

Now Execute,
docker build -t springboot-crud-k8s:1.0 . ; It creates the Docker Image.
kubectl apply -f app-deployment.yaml ; It creates the deployment and services.

IP and Port: 192.168.49.2; 30032

It demonstrates that Docker images and pod services were successfully generated. By the way, what is
“app-deployment.yaml”?
It includes a list of directions that must be given to Kubernetes. The essential information is shown in the
screenshot.

The Dashboard has come to an end. It mentions two installed programs, one of which is "springboot-crud-
k8s-example," which will maintain data in a different application.

Test Results:
What were the Goals?

Pulling a MySql Docker image from Docker Hub


and Deploying by Kubernetes. Status: Done.
Created a CRUD spring Boot applicant and tested.
Status: Done.
Deploy the Application and connected with another
POD where MySql was ruining. Status: Done.
Using the IP address and port where the application
was deployed, test the endpoints. Status: Done.
The End.

You might also like