Developers use different software languages to develop applications. Usually, due to local environment differences, developers observe different outputs from the same codebase. For a smooth development process, this shouldn’t be the case.
This project's aim is preparing Docker containers to standardize the development environments and solve this and similar issues.
To achieve this, I have used Vagrant
for instance provisioning, Kubernetes
as the container orchestration and Ansible
for configuration automation. The project has aimed a demo Python
application but you can use any language depends on your current development software language such as Golang, Java, etc.
There are 3 core steps:
- VM provisioning by using
Vagrant
Kubernetes
cluster installation by usingAnsible
- Application build
script
for building a local image and deploy
- Application has been written by using
Python3
- The application needs a
MySQL
database for datastore - You can build the application by using
build.sh
script. Vagrant
syncs the repo's root folder to the/vagrant
path of the VMs. So you don't need to copy the changed files to the VM for the build process.- The application uses the following environment variables:
- MYSQL_USERNAME
- MYSQL_PASSWORD
- MYSQL_INSTANCE_NAME
- MYSQL_PORT_3306_TCP_ADDR
- MYSQL_PORT_3306_TCP_PORT
- You can able to increase or decrease
Kubernetes
cluster size by editing the environment variables inside of theVagrantfile
. - If you need more instances for testing purposes like application availability test on multi-node, just increase the node size inside of the
Vagrantfile
. - Persistency can be enabled on the Kubernetes cluster by using Persistent Volume (PV) and Persistent Volume Claim (PVC).
- MySQL pod uses PVC for the persistent data store
Vagrant 2.2.9
or later: https://www.vagrantup.com/downloads.htmlAnsible 2.9.12
or later: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-the-control-machine
- 2 VM instances
- Kubernetes cluster - 1 master, 1 node
- Containerized Python application
.
├── LICENSE
├── README.md
├── Vagrantfile
├── app
│ ├── Dockerfile
│ ├── app.py
│ ├── app.yaml
│ ├── mysql.yaml
│ └── requirements.txt
├── build.sh
├── group_vars
│ └── all
├── k8s-configs
│ ├── config
│ └── join-command
├── roles
│ ├── docker
│ │ └── tasks
│ │ ├── install.yaml
│ │ └── main.yml
│ ├── k8s-install
│ │ └── tasks
│ │ ├── install.yaml
│ │ └── main.yml
│ ├── master
│ │ └── tasks
│ │ ├── install.yaml
│ │ └── main.yaml
│ └── node
│ └── tasks
│ ├── install.yaml
│ └── main.yaml
├── setup.yaml
-
Clone
the repository and navigate to the repo'sroot
folder -
Run
vagrant up
command. This will provision2 VMs
which are master and node instances. Then theansible-playbook
will install theKubernetes
cluster as1 master
and1 node
. -
Run
cat ./build.sh | vagrant ssh node-1
command tobuild
anddeploy
the application to theKubernetes
cluster. After the execution, you should see the information like below:
#########
The application is running on the 'busayr/hello-devops-dev:4932133f558e' image.
----------------------------------------------------------
You can access http://192.168.50.11:30300
#########
- You need to run
vagrant provision
after ansible-playbook configuration changes.
- You can remove the environment by using
vagrant destroy
command.
Apache License 2.0