Team 7 Docker Kubernetes WS2021
Team 7 Docker Kubernetes WS2021
Abstract
Due to the portability and ease of reproducible, the containerized
application development became trend among software organizations.
As the number of containers in a system increases the deployment
and managing the containers became difficult. Therefore, container
orchestration tools like Kubernetes offers automatic deployment, scal-
ing, and management of containerized applications. In this paper, we
have explained containerized application deployment into Kubernetes
cluster with Jenkins.
1 Introduction
In past few years, containers have added new dimensions to the way the soft-
ware build, ship, and maintain. A containerized process is highly portable,
and reproducible which enable us to move, and scale container application
more easier than before. Docker is the leading container platform to build,
ship, and run application. It provides loosely isolated environment called
container to package and run application [5].
1
Our goal is to deploy the containerized web application to kubernetes
cluster in public cloud. To bridge the gaps between development, and op-
erational activities (build, test and deployment) of our application we have
implemented Continuous Integration and Continuous Deployment (CI/CD)
process which is the backbone of modern DevOps practice.
The scope of this paper would work as an installation guide that explains
step by step instructions of deployment process of web API. It covers the de-
ployment of container from local to public cloud Kubernetes cluster of both
manual and automated approach.
2 System Overview
Our application is a web REST API service to fetch dummy data from an
in-memory database of application. We have deployed containerized appli-
cation in kubernetes cluster of Google Cloud Platform (GCP) using Jenkins
pipeline. The deployment covers both local, and cloud Kubernetes clus-
ter. Finally, we have automated whole deployment procedures with Jenkins
pipeline.
2
Figure 1: System Architecture
3 Containerization
To create and deploy software faster and more efficiently, containerization
became a major trend in software development [1]. We have used Docker to
create container for our web application. For our local environment, we have
3
installed Docker for Desktop, for detail installation instructions please refer to
reference [2]. Docker builds images automatically by executing instructions
written in Dockerfile which is stored in our source control repository [13].
For a container repository, we have used Dockerhub. With the following
commands we create, run and push Docker container image to Docherhub.
• pods: Each node runs pods which are groups of co-located containers
that share some resources.
4
Figure 2: Kubernetes Architecture [8]
4.2 Deployment
Workloads are scheduled as deployment which are scalable group of pods
maintained by kubernetes automatically. At first, we have deployed our
containers in local kubernetes cluster, then we have deployed in Kubernetes
engine of GCP, and finally, we have automated whole deployment using
Jenkins.
5
With the following commands, we create kubernetes deployments and
services in local kubernetes cluster where name of both deployment, and
service objects is library-cloud-api.
We can scale up and down number of pods either with manual or auto-
matic approach. For example, if we want to increase current number of pods
from three to five, then we can execute following scripts. This is manual
approach.
The above script will increase and decrease number of pods between 1 to
10 based on CPU utilization where we mentioned threshold utilization is 50%.
6
- Authenticate gcloud Tool : gcloud auth configure-docker
5.1 Installation
Firstly, we have created the virtual machine (VM) in GCP to configure Jenk-
ins server with following steps:
- Create a VM instance (debian is default OS) in GCP
- Select both http and https firewall rules from option list
- Select region "europe-west1" (we have selected same region
7
as for kubernetes cluster but any region can be selected)
5.1.1 JDK
Jenkins needs Java to run, so we have installed JDK. Execute following
commands to install openjdk-8.
5.1.3 Docker
We have used Docker to create container of our web application, so Jenkins
server needs Docker to be installed by following commands [4].
8
$(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get install docker-ce docker-ce-cli containerd.io
We also need to add users to docker group, and restart Jenkins server
with following command
5.1.4 kubectl
It is a command line tool to control kubernetes cluster. We have installed
kubectl with following commands:
5.1.5 Jenkins
With the following commands [3], we have installed Jenkins in server. We
have used wget to download Jenkins from internet. Prior to install Jenkins,
we have installed wget.
9
5.2 Activation
Browse the Jenkins by clicking the external IP of Jenkins VM from google
cloud. But the site might not accessible as port 8080 might not be already
opened. So, we must create a firewall rule to allow all traffics on port 8080.
To do that, follow the steps mentioned below.
For the first time, Jenkins needs to be activated by providing it’s secret
stored in server. Secret is stored in file initialAdminPassword in directory
/var/lib/jenkins/secrets. Follow below steps to fetch the secret.
cd /var/lib/jenkins/secrets
nano initialAdminPassword
copy the secret
After submitting the secrets, select install Jenkins option, then it will
start installation. After installation, it will let us create another user, and
password which we can later usable for the login Jenkins from browser.
10
5.3.2 Plugins
Install following plugins
- Docker Pipeline
- Kubernetes
- Kubernetes Continuous Deploy
- Google kubernetes engine
5.3.3 Credentials
Go to Manage Credentials in Jenkins, and create credentials for the following
service.
- DockerHub
- Google Cloud Kubernetes Engine
We also need to ensure that the service account in GCP has access to the
Google Kubernetes Engine. We can ensure that with following steps:
5.3.4 Pipeline
To create a pipeline from Jenkins user interface, click New Item and then
follow below steps:
- Select pipeline
- Select github project (and give project url)
- Select build triggers +it["github hook trigger for GITScm polling"]
- In pipeline select "Pipeline script from scm"
- Provide git repository url and branch information
11
- Push Docker image to Dockerhub: Using Docker Pipeline plugin, it
pushes the image to Dockerhub (container repository)
- Deployment to GKE: Finally deploy to Google Kubernetes cluster.
It uses a Kubernetes manifest file stored in source
control repository [12] to create deployments and services.
Execution of Jenkins pipeline will display the status, and time what it
took to complete each stage defined in Jenkinsfile [14], see the figure (3.
12
Figure 4: Local cluster
The above command will list all nodes, pods, and services running in
local kubernetes cluster like in figure 4.
The above command will list nodes, pods and services which are created
in kubernetes cluster (see the figure 6).
13
Figure 5: Access to Service
14
Figure 7: Access to the service
6.3 Jenkins
We have discussed how to configure Jenkins and create Jenkins pipeline in
section 5. In this section we will check our deployments done by Jenkins.
Figure 8 shows the deployment status. It displays nodes, pods, and ser-
vices which are created by Jenkins pipeline execution.
Now our service is exposed and accessible publicly, (see figure 9).
15
Figure 9: Access to the services (deployed by Jenkins)
7 Conclusion
This paper has discussed the container deployment to Kubernetes cluster and
explained our approaches to do so. It includes step-by-step instructions to
configure and install necessary tools and services. Finally, we have covered
the procedures to test deployments, and discussed the deployment outcomes.
References
[1] ”What is containerization?”, by IBM Cloud Kubernetes Service
(https://www.ibm.com/cloud/learn/containerization)
16
[5] ”Docker overview”, by Docker official documents page
(https://docs.docker.com/get-started/overview/)
17