In a modern development environment, continuous integration and development are central to the success of a software development project. To be successful when using a Continuous Delivery approach, you need to avail short lived development and test environments for handling code changes. The ability to quickly create and terminate containers in Docker and Kubernetes is a feature that very well supports the continuous delivery model. In this tutorial, we will abbreviate continuous development/continuous integration as CI/CD.
As a developer, CI/CD offers you an opportunity to develop better software and quickly deliver solutions to your clients. Despite the benefits offered by CI/CD, you will face challenges in implementation because of the large number of micro services you need to handle as well as keeping up with innovations related to containers. Tools have been developed to support developers and in this we will discuss how we can use Jenkins and Fabric 8 in implementing CI/CD. Another tool that can be used to implement CI/CD is Gulp, but we will not discuss it in this tutorial because of space limitations.
Fabric 8 is an open source platform which offers you an environment to implement CI/CD. Continuous delivery is enabled through micro-services creation, building, testing and deployment. Continuous improvement is enabled through tools to run and manage CD pipelines. Fabric 8 can be used together with Docker, Kubernetes, Google Container Engine and OpenShift V3.
The features that are provided by Fabric 8 are briefly mentioned below: –
A web based developer console which enables creation, editing, deployment and testing of micro-services.
Management tools for central logging, metrics collection and Java container management.
Apache Camel integration, RESTful and SOAP API visualization and management
Java tools to enable Java developers fully exploit Kubernetes.
Implementing CI/CD using Jenkins
To install gofabric 8 on a local Linux computer you first need to install the kvm driver. The commands below are used to download version 0.7.0 to a specific directory and install it.
sudo curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm -o /usr/local/bin/docker-machine-driver-kvm sudo chmod +x /usr/local/bin/docker-machine-driver-kvm sudo apt install libvirt-bin qemu-kvm
The command below will install gofabric 8.
curl -sS https://get.fabric8.io/download.txt | bash
To complete installation, we need to add gofabric 8 to our path. Open bashrc in an editor, add the path at the end, save and reload.
To start a cluster and download the tools needed to run a single node cluster, use this command
After starting your cluster, you can open the browser console using this command gofabric8 console.
In the previous section, we demonstrated how to run a cluster locally. The easiest way to set up gofabric in the cloud is through stackpoint which supports Amazon, Google and Azure public clouds. Login to your stack point account here https://stackpoint.io. After logging in, click on select a provider then choose the cloud you would like to use. In this tutorial, we will demonstrate the use of Google Compute Engine (GCE) so, select that. To connect to our cloud, we need to provide credentials. To create credentials login to your GCE console here https://console.cloud.google.com and create a new project. Click on Products and Services, API manager, Credentials and then select service account key.
After creating your key, copy and paste it in credentials box on Stackpoint, then click create, and click on submit.
Provide a cluster name and any customizations you need, then click on submit.
Your cluster will be created.
To start using our cluster, we need to wait for the cluster to complete building, download kubeconfig, export kubeconfig path and set its context using the commands below.
export KUBECONFIG=~/Downloads/kubeconfig kubectl config use-context stackpoint
We can then check our cluster information using this command
kubectl get nodes
Another technology that we can use to implement CI/CD is Jenkins. A plugin is available in the form of a Docker container to simplify Jenkins setup. To pull the image and create a container, we can use the commands below.
sudo docker pull csanchez/jenkins-kubernetes sudo docker create --name jenkins-k8s csanchez/jenkins-kubernetes
The above approach to setting up Jenkins data will be stored in jenkins-k8s container.
To use another container for data storage, we can setup Jenkins using the command below.
sudo docker run --volumes-from jenkins-k8s -p 8080:8080 -p 50000:50000 -v /var/jenkins_home csanchez/jenkins-kubernetes
After setting up Jenkins successfully, the message shown below will be displayed.
After creating our container we need to navigate to http://localhost:8080 and login as admin user using the password provided to start configuring Jenkins.
After logging in you will be requested to install the most useful plugins to the Jenkins community or select plugins you would like to install. After the plugins are installed, you will be notified of successful installation.
The first configuration we need is creating an admin user. Provide information required such as user name, password and email address.
Create a new job. You will need to provide project settings such name and project type among others.
To configure Kubernetes settings, click on Manage Jenkins, Configure System, Cloud, Add a New Cloud, then Kubernetes. Fill in the required parameters depending on your environment. An example of information required is shown below. After providing information, click on save and apply.
When you would like to use Jenkins as one of your slaves, there is a jnlp-slave image available on Docker hub.
In this post, we introduced CI/CD and noted it provides developers with benefits but presents some challenges. We noted Jenkins, fabric 8 and Gulp are technologies that have been developed to support implementation of CI/CD in Kubernetes. We demonstrated how to install kvm driver and set up a gofabric 8 cluster locally. We also demonstrated how to setup a kubernetes cluster on GCE using Openstack. Finally, we demonstrated how to set up Jenkins.
The post Learn How Continuous Delivery is Implemented in Kubernetes appeared first on Eduonix.com | Blog.