0% found this document useful (0 votes)
10 views

Module-5

Uploaded by

suneetha prabhu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Module-5

Uploaded by

suneetha prabhu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Suppose asked with the creation of Docker Image along with Kubernetes cluster

Creation of Docker Image


After installing our Kubernetes cluster, we will deploy an application in it. First of all, it
is important to know that when we deploy an application in Kubernetes, we create a new
instance of the Docker container in a Kubernetes pod object, so we first need to have
a Docker image that contains the application.
To deploy this instance of the Docker container, we will create a new k8sdeploy folder,
and inside it, we will create a Kubernetes deployment YAML specification file
(myappdeployment.yml) with the following content.

apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp
spec:
selector:
matchLabels:
app: webapp
replicas: 2
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: demobookk8s
image: mikaelkrief/demobook:latest
ports:
- containerPort: 80
In this preceding code snippet, we describe our deployment in the following way:
• The apiVersion property is the version of api that should be used.
• In the Kind property, we indicate that the specification type is deployment.
• The replicas property indicates the number of pods that Kubernetes will create
in the cluster; here, we choose two instances.
Then, in the containers section, we indicate the image (from Docker Hub) with name
and tag. Finally, the ports property indicates the port that the container will use within
the cluster.
To deploy our application, we go to our Terminal and execute one of the essential
kubectl commands (kubectl apply), as follows:
kubectl apply -f myapp-deployment.yml
The -f parameter corresponds to the YAML specification file.
This command applies the deployment that is described in the YAML specification file on
the Kubernetes cluster.
kubectl get pods command, which returns a list of cluster pods.
What we can see in the preceding screenshot is that the second command displays our
two pods, with the name (webapp) specified in the YAML file, followed by a unique
identifier (UID), and that they are in a Running status.
We can also visualize the status of our cluster on the Kubernetes web dashboard, the
webapp deployment with the Docker image that has been used, and the two pods that
have been created.
Kubernetes architecture overview and Installation of Kubernetes on a local machine

Kubernetes is a platform that is made up of several components that assemble together


and extend on demand, in order to enable better scalability of applications. The
architecture of Kubernetes, which is a client/server type, can be represented simply, as
shown in the following diagram:

In each of these nodes, there are pods, which are virtual elements that will contain
containers and volumes.
Put simply, we can create one pod per application, and it will contain all the containers
of the application. For example, one pod can contain a web server container, a database
container, and a volume that will contain persistent files for images and database files.
Installing Kubernetes on a local machine
1. If we have already installed Docker Desktop,
, Containerizing Your Application with Docker, we can activate the Enable
Kubernetes option in Settings on the Kubernetes tab.
2. After clicking on the Apply & Restart button, Docker Desktop will install a local
Kubernetes cluster, and also the kubectl client tool, on the local machine.
creating collection and creating request with postman
create a DemoBook collection that will contain the requests to the demo API, and for this, we will perform the
following tasks:
1. In Postman, in the left-hand panel, click on the Collections | + button.
2. Once the tab opens, we will enter the name DemoBook.

These properties include request authentication, tests to be performed before and after requests, and variables
common to all requests in this collection. To modify the settings and properties of this collection, perform the
following actions:
1. Click on the ... button of the context menu of the collection.
2. Choose the Edit option, and the edit form appears, in which we can change all the
settings that will apply to the requests in this collection.
3. Switch between all configuration tabs for the edit authorization, scripts, tests, or
variables options.
Creating our first request
The main parameters of a request are as follows:
• The URL of the API
• Its method: GET/POST/DELETE/PATCH
• Its authentication properties
• Its query string keys and its body request
• The tests that are to be performed before or after execution of the API
1. The creation of the request: To create the request of our API, here are the steps that need to be followed:
I. We go to the context menu of the DemoBook collection and click on the Add
Request option:
II. Then, in the new tag, enter the name of the request, Get all posts.

2. The configuration of the request: After creating the request, we will configure it by entering the URL of the
API to be tested, which is https://jsonplaceholder.typicode.com/posts, in the GET method.

You might also like