Kubernetes
Kubernetes
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.
He shared with me the challenges they are facing and to get over this point, I introduced him two things.
1. Microservice:
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
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.
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.
In the subsequent article, I will show the installation to deploying an application to analyzing the
dashboard for Kubernetes.
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”.
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.
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.
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
So, the instructions are ready, let’s say all are saved into the file named “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.
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.
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.
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.
Work Progress:
Spring Boot App; Status: Done.
Docker Image; Status: In progress.
Kubernetes Deployment; Status: In progress.
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.
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?