High availability infrastructure with automated deployment

Simarpreet Singh Gujral
Akeo
Published in
4 min readNov 15, 2019

With the introduction of dockers, deployment of applications has become painless for both developers and system administrators. Moreover, the DevOps ecosystem has reached a level where it makes deployment of applications easier and faster than before.

Inside our company, we have also been regularly practicing a lot in the DevOps arena. We are keeping pace with the development in technology, and now all of our projects are deployed and maintained through automation scripts. A part of this practice involves using Kubernetes and Docker in various automated deployments and testing.

I thought why don’t we write a series of blogs where we help others to implement the same in both development and production environment. We would be covering a lot of hands-on experience, we have had in our development lab to automate the deployment of different applications like Java, Dotnet Core, PHP, Nodejs, Python, etc. In this series, we will be covering deployment only through Kubernetes and Dockers.

To start with the setup, let us have a quick look at how the infrastructure will look like and what all components will be required to have a fully functional environment.

  • The first thing we require is an Ubuntu machine (the steps in this blog were tested on Ubuntu16.04 machine).
  • Git repository that has a working code in any of the programming languages.
  • Jenkins server to build the docker image and push it to a private docker repository which we will look at how to set up in this tutorial.

You can also use any other repositories of your choice like docker hub. We recommend to configure firewall and port restrictions on the server that will host the application.

So, let us begin by setting up the environment for automated deployment magic to happen.

Step 1: Setup the private Docker Repository

  • Installing docker
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -- sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”- sudo apt-get update- sudo apt-get install -y docker-ce
  • Installing docker-compose
- sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose- sudo chmod +x /usr/local/bin/docker-compose
  • Installing docker registry
- mkdir ~/docker-registry && cd $_- mkdir data- nano docker-compose.yml
  • File view
version: ‘3’services:registry:image: registry:2ports:- “5000:5000”environment:REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /datavolumes:- ./data:/data- docker-compose -f docker-compose.yml up -d

Step 2: Setup the Kubernetes for deployment

  • To setup Kubernetes on Ubuntu, please follow this article

Step 3: Add dockerfile to your repository

  • Now, we will deploy a sample application on docker container using dockerfile. Please create a dockerfile with the contents mentioned below and add them to the code repository
FROM httpd:2.4COPY ./index.html/ /usr/local/apache2/htdocs/EXPOSE 80The contents of index.html can be:<html><head><title>Our Sample Application</title></head><body><h1>Welcome</h1></body></html>

Step 4: Setup and Configure Jenkins

  • Installing jenkins
- wget -q -O — https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -- echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list- sudo apt-get update- sudo apt-get install jenkins- sudo systemctl start jenkins
  • Configure Jenkins using the url http://ip_address:8080 This will prompt for the administrator password
  • Grab the default password using the below command and paste in the above screen
- sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  • Install the suggested or custom plugins. Then create the first admin user and start using Jenkins!

Step 5: Deploy the first application

  • Creating Jenkins job
  • Open the jenkins url and click on “New Item”
  • Provide a name for the job and select freestyle job
  • Provide the git repository url and credentials for cloning the project. Also specify the branch
  • Select “Execute Shell” from the add build step
  • Provide the steps as shown
  • Save the job and execute it
  • This will create docker image and push to the private docker registry
  • The above image can be pulled and used on any machine. To use the image to run the sample application execute the below commands
sudo docker pull ip_address_of_registry:5000/sample-application-imagesudo docker run — name cnt_name -d -it -p 8060:80 ip_address_of_registry:5000/sample-application-image

Finally we have the working environment and we are ready to onboard more applications on the same server. In our upcoming articles (mentioned below) we will write about how to build and deploy different types of applications, do watch out for them!

  1. Deploy Dotnet applications using Kubernetes
  2. Deploy Node.Js applications using Kubernetes
  3. Deploy Python applications using Kubernetes
  4. Deploy PHP applications using Kubernetes
  5. Deploy Java applications using Kubernetes

--

--