Installation of BuildOn

Setup guidelines

 Hardware Configuration

Kubernetes Master & Node configuration
No. of instances3 - 1 Master, 2 Nodes 
AWS Instance typem3.xlarge
OSUbuntu 16.04 Xenial (64bit) 
Storage200 GB
Mem (GiB)15GB
vCPU4
Configuration varies depending on the work load.
 Software
  • Kubernetes version : 1.10.0
  • Docker version : 1.13.1
  • Python version : 3.5
  • Jenkins : 2.121.1
  • Postgres DB: 9.6.11
 Recommended Network Ports
  • Kube API Server : 6443
  • Python service : 5000
  • Postgres DB : 5432
  • Jenkins docker container host : 8080
  • Apache Tomcat : 443
 Installation of Kubernetes Cluster

Connect to AWS EC2 instance from Windows using PuTTY

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

Execute the following commands in the Master and Slave machines

  1. Switch to the root user (sudo su)
  2. apt-get update && apt-get install -y apt-transport-https
  3. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  4. cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
  5. apt-get update
  6. apt-get install docker.io 

  7. To Install a specific version(v1.10.0):  apt-get install -y kubeadm=1.10.0-00 kubectl=1.10.0-00 kubelet=1.10.0-00 kubernetes-cni

    To Install latest version for k8s, refer the following example commands

    apt-get install -y kubelet kubeadm kubectl kubernetes-cni

    OPTIONAL : Run docker as daemon in both Master and Slave nodes as given below:

          Open /lib/systemd/system/docker.service

          Add the below line and save the file:

          ExecStart=/usr/bin/dockerd -H fd:// -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376 $DOCKER_OPTS

          Execute the following commands to reload and restart docker

          systemctl daemon-reload
          systemctl restart docker


Allow tcp ports Kube API : 6443, Weave net: 6783 , etcd api: 2379-2380, kubelet API: 10250, kube-scheduler: 10251,kube-controller-manager: 10252  between kubernetes master and kubernetes slave machines for the kubernetes cluster services to communicate. Master will try to create the pods in slave instances and the same will be blocked if the ports are not opened between master/slave. Refer: https://kubernetes.io/docs/setup/independent/install-kubeadm/#check-required-ports

Execute the following commands in the Master Machine

  1. # kubeadm init

        In case, kubernetes cluster configuration located in $HOME/.kube/config then run the following command

       To start using your cluster, run below commands:

          mkdir -p $HOME/.kube

          sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

          sudo chown $(id -u):$(id -g) $HOME/.kube/config

          export KUBECONFIG=$HOME/.kube/config

Add “export KUBECONFIG=$HOME/.kube/config” to ~/.bashrc file in order to export the conf file. If this is not added, the export will be applicable only to the current putty session. For a new session, the Kubernetes API will be unreachable.

    In case, kubernetes configuration located in $HOME/admin.conf then run the following command

    To start using your cluster, run below commands as root user or prefix with sudo:

          cp /etc/kubernetes/admin.conf $HOME/

          chown $(id -u):$(id -g) $HOME/admin.conf

          export KUBECONFIG=$HOME/admin.conf

Add “export KUBECONFIG=$HOME/admin.conf” to ~/.bashrc file in order to export the conf file. If this is not added, the export will be applicable only to the current putty session. For a new session, the Kubernetes API will be unreachable.

2. In order to communicate on the k8s cluster network, used "Weave Net" as a network overlay. Run the following commands in the Master.

         # kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

Check the following reference link to install any other Addons for network overlay in k8s.

https://kubernetes.io/docs/concepts/cluster-administration/addons/

3. Kubernetes dashboard is an optional step. To create Kubernetes dashboard, refer "Deploying the Dashboard UI" in https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ to know the correct kubernetes-dashboard.yaml  github url. (OR)  https://github.com/kubernetes/dashboard/wiki/Installation

Run the following commands: -

          # kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta1/aio/deploy/recommended.yaml

     (OR)


          # kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/alternative/kubernetes-dashboard.yaml

Dashboard will run as a Kube service either in the Master or in any one of the Slaves. Run “kubectl get svc --all-namespaces” to identify the PORT number of the dashboard. Access the dashboard through https://IP:PORT.

4. Create a cluster role and bind all services then allow anonymous user to access Kube API

 If the below kubectl commands are not executed, you will get an error - 'User "system:serviceaccount:default:default" cannot list pods in the namespace "default"'       

        # kubectl create clusterrolebinding serviceaccounts-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccounts

        # kubectl create rolebinding bob-admin-binding --clusterrole=admin --user=system:anonymous --namespace=default 

     (OR) Use below authentication token (preferred one)

       # curl -k `(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")`/api/v1/namespaces/default/pods/web/log --header "Authorization: Bearer `(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')`"

Execute the following commands in the Slave machines to connect to the Master machine

  1. After kubeadm init, you will obtain a token as shown below -

# kubeadm join --token <token id> <Primary IP>:6443

Execute it in the slave machines.

kubeadm join command for latest version is show below:

kubeadm join <Primary IP>:6443 --token <token id> --discovery-token-ca-cert-hash <sha256:3ab48bab75c-ca-cert-hash-43ab4fdsfdsfb0cc16c3d8b65d8a664a959>

2. Post execution, go to the Master machine and run “kubectl get nodes”, and verify if the nodes have joined the cluster.

3. Verify if all pods are up and running.

#kubectl get pods --all-namespaces

You will get an output similar to the one shown below -

4. Also, Verify k8s cluster setup by running a particular sample images like busybox,nginx etc.,  in the master (as given in the following link https://kubernetes-v1-4.github.io/docs/user-guide/kubectl/kubectl_run/) to confirm that pods are running and containers are spawned in the slaves.

 BuildOn Framework Setup

BuildOn Scripts

Following are the mandatory files to be located under the directory "/home/Ubuntu/BuildOn" to execute the BuildOn.

List of Scripts/JARs
S.NoScript nameDetails
1app.pyPython service (web-hook)
2buildon.pyContains the logic to retrieve payload values, insert Buildon commit record to DB, run Kubernetes Pod
3dbupdate.pyUpdates Jenkins live job’s status to 'buildon_reports table'
4buildon.propertiesContains Kubernetes master IP ,framework port, PostgreSQL details, Logbase path, Bitbucket (IP, port, service account user, personal access token)

Python 3 in Kube Master

As of Ubuntu 16.04 LTS (xenial),  python3 is default. Check and then install if required.

  1. apt-get install python3.5
  2. apt-get install python3-pip

set alias to respectiive python version in ~/.bashrc to avoid error while installing the module.

alias pip=pip3

alias python=python3.5

(OR)

Use direct pip version to install module as shown below.

For example:

pip3 install wget

Python modules to be installed in Kube Master

Run the following commands to install Python modules in Kubernetes Master Server.

  1. pip install wget
  2. pip install docker==2.0.0
  3. pip install pytz
  4. pip install elasticsearch
  5. pip install configparser
  6. pip install gunicorn
  7. pip install gevent
  8. pip install app

  9. pip install flask

  10. pip install pg8000


In case, any other modules are left out while executing app.py, please install them as well.

Execution of Python service

Run the following command from /home/ubuntu/BuildOn folder where app.py located to keep the service always up and running

# nohup  gunicorn -k gevent -b 0.0.0.0:5000 -w 2 --timeout 90 app:app > framework.log &

 PostgreSQL Setup

PostgreSQL DB usage in BuildOn

PostgreSQL is used to store the extracted data from SCM payload and framework in the DB tables buildon_users, buildon_scmdetails, buildon_preferences, buildon_reports and buildon_servcies. Refer the installation steps to setup PostgreSQL DB for BuildOn.

Installation Steps

Run the following command to setup PostgreSQL

#apt-get install postgresql postgresql-contrib  ## postgresql will be installed and started on port 5432

How to connect PostgreSQL ? 

#sudo -i -u postgres

# psql

Setup postgres password: To enable authentication. BuildOn ui/framework application will connect using these credentials.

postgres=# \password postgres
Enter new password:
Enter it again:

Accessing the buildonUI URL in the browser will create required DB tables automatically. Setup the BuildOn application before creating buildon login user in DB.

Create login user in buildon_users db table (using below query) to login through buildon UI.

postgres=#  insert into buildon_users(uname,upass,email) values ('username','password','email@orgname.com');


BuildOn Framework Setup without UI will not create required BuildOn tables automatically. In such case, use the attachment "create_buildon_tables.sql" in this page to create buildon tables in postgreSQL.

 BuildOn Application Setup

BuildOn application is deployed on Apache Tomcat 8.0.39 server.

Connect to AWS EC2 instance from Windows using PuTTY

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

Apache Tomcat installation steps (as tar file)

  1. cd /home/ubuntu
  2. curl -O https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz
  3. tar xzvf apache-tomcat-8.0.39.tar.gz
  4. Start tomcat "/home/ubuntu/apache-tomcat-8.0.39/bin/startup.sh"

BuildOn application deployment

Deploy the buildon.war using one of the following methods:

  • Tomcat Manager console 
  • Directly place the buildon.war file in webapps folder(/home/ubuntu/apache-tomcat-8.0.39/webapps)

Post successful deployment of BuildOn, application will be accessible @ https://buildon.cogdevops.com/buildon  

Apache Tomcat as a Service - installation steps 

apt-get install tomcat8

apt-get install tomcat8-docs tomcat8-examples tomcat8-admin

service tomcat start | stop | restart

Enable SSL in tomcat

https://syslint.com/blog/tutorial/how-to-add-ssl-certificate-for-a-domain-in-tomcat-8-server/

Note: Tomcat is advised to be installed as a Service for proper functioning of applications interacting with Git APIs.

 BuildOn Application - LDAP Configuration

LDAP configuration in BuildOn

  1. Locate buildon.properties under buildon application resources folder (src/main/resources/buildon.properties)
  2. Set isLDAP=true to use the LDAP for login; isLDAP=false to use DBtable for login, For LDAP set values - ldap.user and ldap.password and isLDAP to true and isopenLDAP to false
    ldap.isLDAP=true
  3. LDAP server ip and port
    ldap.server=LDAP://<ldap-server-ip>:<ldap-port>
  4. ldap service account username and password to fetch the the user's details
    ldap.user=<serviceaccount-username>
    ldap.password=<serviceaccount-password>
  5. ldap searchbase attributes
    ldap.searchbase=DC=<domain>,DC=<com> 
  6. To use openLDAP anonymous user ldap.user and ldap.password set to empty and isLDAP to false
    ldap.isopenLDAP=false
  7. Compile and package the code using maven . Deploy the war (buildon.war) to Apache Tomcat Server.