Malith's Perspective

Sunday, May 28, 2017

Using fabric8 docker-maven-plugin to automate docker builds

No comments : Posted by Unknown at 1:37:00 AM Labels: #docker , #docker-maven-plugin , #fabric8 , #Kubernetes
In building the required libraries for a docker container, using a maven project, the libraries have to be copied to a separate location and we have to manually run a docker build. This process is cumbersome since you have to repeat the same process over even if there is a slight modification.

fabric8 docker-maven-plugin is the perfect solution for this requirement. spotify also supports a docker plugin. However fabric8 provides much more functionalities. For example, with fabric8 it's possible to inject values to the docker file with ease.

fabric8 provides a great source of documentation (https://dmp.fabric8.io/). However for a beginner, it could be challenging. My requirement was to configure the plugin in
 such a way that would enable even a user without docker on his/her machine to do a maven build.

The first step was to move the variable names to the POM so that configurations can be separated in order to improve maintainability.


        <fabric8io.docker.version>0.21.0</fabric8io.docker.version>
        <docker.registry>myregistry.malith.com:5000</docker.registry>
        <docker.image.tag>latest</docker.image.tag>
        <docker.repository>projectname:${docker.image.tag}</docker.repository>
        <docker.fileName>Dockerfile</docker.fileName>
        <docker.skip>false</docker.skip>


Next under the <build><plugins> tag add the maven docker plugin.

              <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${fabric8io.docker.version}</version>
                <configuration>
                    <registry>${docker.registry}</registry>
                    <useColor>true</useColor>
                    <verbose>true</verbose>
                    <skip>${docker.skip}</skip>
                    <images>
                        <image>
                            <name>${docker.registry}/${docker.repository}</name>
                            <build>
                                <dockerFileDir>${project.build.directory}/projectname-${project.version}-docker/projectname</dockerFileDir>
                                <filter>@</filter>
                                <dockerFile>${docker.fileName}</dockerFile>
                                <tags>
                                    <tag>${docker.image.tag}</tag>
                                </tags>
                            </build>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <!-- "build" should be used to create the images with the
                                 artifact -->
                            <goal>build</goal>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Next, I needed to skip the execution of the plugin if the user does not want to build the docker image. Therefore I created a profile, that would set the variable ${docker.skip} to true on the provision of the variable skipDocker.

I added the following section to the pom.


 <profiles>
        <profile>
            <id>docker</id>
            <properties>
                <docker.skip>true</docker.skip>
            </properties>
            <activation>
                <property>
                    <name>skipDocker</name>
                    <value>true</value>
                </property>
            </activation>
        </profile>
    </profiles>

Based on the above code snippet, if skipDocker has been given as a maven directive, it would set docker.skip to true, effectively skipping the execution of the plugin.

Therefore a user can skip building the docker image simply by,


maven clean install -DskipDocker

Fabric8 has a lot of support for docker builds. I have a lot to explore. Hope you've found my findings useful. Don't forget to leave a comment. :-) 
Read More

Saturday, May 27, 2017

Setting up Kubernetes 1.7 on a CentOS 7.1 cluster

No comments : Posted by Unknown at 9:16:00 PM Labels: #CentOS , #Cluster , #docker , #Kubernetes
It was quite a daunting task at the beginning to start with Kubernetes 1.7 alpha release because I knew that I was bound to face with difficulties. I built Kubernetes from source on my Ubuntu 16.04 machine.

I downloaded the source from kubernetes (https://github.com/kubernetes/kubernetes/tree/v1.7.0-alpha.3) and CentOS 7.1 (minimal version). I set up three virtual machines to deploy my CentOS cluster. This blog post focuses on building and deploying Kubernetes.

First I navigated to the kubernetes src folder within kubernetes.

cd kubernetes/src/k8s.io/kubernetes/

Then I built the kubernetes images with,

build/run.sh

In order to build the relase binaries execute,

build/release.sh

When I executed this I ran out of space in my root directory. This was due to the fact that in /var/lib/docker Docker creates a large number of layers eating up disk space. It could run up to a dazzling amount of 30GB. So I had to move the kubernetes src to another partition and I created a symlink from /var/lib/docker to /media/malith/Data/docker/ which was on the Data partition.

Next we need to copy the download etcd, falnnel and docker. But we do not need to download kubernetes as we have built it. If we download it, there would most probably be a version incompatibility.

Therefore comment out the below section.

#echo "Download kubernetes release v${K8S_VERSION} ..."
  #curl -L ${K8S_CLIENT_DOWNLOAD_URL} -o ${RELEASES_DIR}/kubernetes-client-linux-amd64.tar.gz
  #curl -L ${K8S_SERVER_DOWNLOAD_URL} -o ${RELEASES_DIR}/kubernetes-server-linux-amd64.tar.gz

In the function download-release() comment

#rm -rf ${RELEASES_DIR}

This is due to the fact that we are trying to move the binaries that we built to the RELEASES_DIR directory which defaults to /tmp/downloads.

Next we have to manually copy kubernetes-client-linux-amd64.tar.gz and kubernetes-server-linux-amd64.tar.gz to the RELEASES_DIR folder. You can find them by navigating to the folder,

cd kubernetes/src/k8s.io/kubernetes/_output/release-tars

Okay, we are good to go. Now we can start a cluster, provided you have a minimum of three CentOS machines on a private network with an active internet connection.

You need to change the following values in cluster/centos/config-default.sh. My master IP address is 192.168.57.122 and the minions are respectively, 192.168.57.123 and 192.168.57.123.

export MASTER="root@192.168.57.122"
export NODES="${NODES:-"root@192.168.57.123 root@192.168.57.124"}"

Do not change the DNS Server IP as it's configured by Kubernetes itself.

To start kubernetes, navigate to the cluster folder,

KUBERNETES_PROVIDER=centos CERT_GROUP=malith ./kube-up.sh

However I kept running into an error due to a fault with kubernetes. It could not read a variable value (MASTER_ADVERTISE_ADDRESS)

Therefore I had to edit cluster/centos/util.sh. In the function "make-ca-cert", I added the line
MASTER_ADVERTISE_IP=192.168.57.122.

After that I executed the above command again, and the cluster started successfully.



Read More
Newer Posts Older Posts Home
Subscribe to: Posts ( Atom )

R-bloggers

Loading...

Navigation

  • Home
  • Twitter

About Me

Unknown
View my complete profile

Blog Archive

  • 2017 (2)
    • May (2)
      • Using fabric8 docker-maven-plugin to automate dock...
      • Setting up Kubernetes 1.7 on a CentOS 7.1 cluster
  • 2016 (4)
    • August (4)
  • 2014 (2)
    • December (2)

Popular Posts

  • Gauge Meters; A daunting task
    Since I'm on vacation, I thought of planning my project using the free time. As the next step, I thought of developing the front end of...
  • Using fabric8 docker-maven-plugin to automate docker builds
    In building the required libraries for a docker container, using a maven project, the libraries have to be copied to a separate location an...
  • postCP change point detection with GSOC
    Introduction The project aimed at improving the postCP package and making it available on CRAN again. The snag that prevented the pac...
  • My Experience with GSOC and R
    It all began when I started searching for a Google Summer of Code project last year (November, 2015) . While I was searching through the we...
  • Changepoint Detection : Theoretical Background
    Introduction  Changepoints are abrupt variations in the generative parameters of sequential data. Changepoint detection is the process o...
  • Conquering Raspberry Pi with Ubuntu 14.04 : Resolving issues with Partitioning
    Recently for a project, I used a Raspberry Pi. Although mostly it's preferred to use raspbian as an operating system, I chose to use U...
  • Air Conditioning? Big Deal?
    Last week we were assigned projects for our 4th semester and I was selected for the energy sector. As a part of it, when I was exploring t...
  • Setting up Kubernetes 1.7 on a CentOS 7.1 cluster
    It was quite a daunting task at the beginning to start with Kubernetes 1.7 alpha release because I knew that I was bound to face with diffi...
Powered by Blogger.

Labels

#GSOC (3) #Tech (3) #postCP (3) #Kubernetes (2) #R-gsoc (2) #docker (2) #CentOS (1) #Cluster (1) #Pi (1) #R (1) #Ubuntu (1) #docker-maven-plugin (1) #fabric8 (1) #raspberryPi (1) Air Conditioning (1) Embedded (1) Micro Controllers (1) Power consumption (1) Smart Systems (1) Tech (1)

© Malith's Perspective 2016 . Powered by Bootstrap , Blogger templates and RWD Testing Tool