In this write-up, I will be using open-source software’s to build a fully functional CI/CD pipeline that allows you to take code from a repository, build, commit, publish and deploy docker based images onto a Kubernetes 1.18 cluster – all by issuing in a git commit to your repository.
Building Sandbox (Developer Box)
Sandbox is a CentOS 7.3 based host, which serves applications you need in the CI/CD pipeline.
Software Available on the Sandbox:
· Gnome Desktop
· Docker Daemon and Engine
· git tools
· pyenv
· Python 2.7
· pip
· virtualenv
· drone command line tool
· PyCharm (Community)
· node version manager (nvm)
· node v6.9.2 (LTS)
CI/CD Pipeline workflow

Gogs - Self-Hosted Git Service (https://gogs.io/)
Drone - Continuous Delivery System (https://www.drone.io/)
Kubernetes – Container Management Platform (https://kubernetes.io/)
In this CI/CD environment the developer can:
1. Store, commit and manage your code in Gogs
2. Automatically build a docker container from a code repository, using Drone
3. Automatically store that container on Docker Registry, using Drone
4. Automatically deploy the container to a Kubernetes pod!
Gogs:
Gogs is a private source code control system anyone can deploy locally, written in Go. I use it as a public GitHub alternative here.
We can create, manage and commit our code exactly as we would with GitHub. With this CI/CD Pipeline, we can then quickly see our code built into a container and deployed automatically onto Kubernetes by Drone.
Drone:
Drone is a CI/CD tool, which can pull our code from Gogs and build/publish/deploy it to Kubernetes nodes or other targets.
For Drone to be able to know how to execute a CI/CD pipeline for us, it uses three main stages:
Build - Builds your code from a repo kept in a store like Gogs
Publish - Takes our code, builds it into a container, and pushes it to a container repo like Docker Hub
Deploy - Deploys the container from the repo to the target platform - e.g., Kubernetes.
There are many other options here, but these are the main items.
Drone expects these stages to be built into a .yml file.
pipeline:
publish:
image: plugins/docker
dockerfile: Dockerfile
repo: drone:5000/busybox-sandeep
registry: drone:5000
insecure: true
tags: "${DRONE_BUILD_NUMBER}"
deploy:
image: devnetsandbox/kube
kubernetes_server: http://master:8001
kubernetes_token: <Your Kubernetes Token>
namespace: default
deployment: application1
container: busybox-sandeep
repo: drone:5000/ busybox-sandeep
registry: drone:5000
insecure: true
tag: "${DRONE_BUILD_NUMBER}"
Create Docker File in the repository

Upload the .yml file to your Git Repository

Git Clone the Repository

Once the commit is done – The Webhook will auto-sync and runs the pipeline.

Deployment in Progress


Deployment Completed

Kubernetes Deployment


kubectl describe pod - to get the deployment IP
