Learn about components to setup local development environment here.

...

Kubernetes Environment-Creates base environment required to execute and maintain Bots. Kubernetes spawn docker image with base Ubuntu 16.04 with additional software's like NodeJS,CoffeeScript,npm e.tc.
Elastic Search-Holds logs,metrics related information
MongoDB - Used to maintain Approval flow. Generates and Maintain Ticket related information.
MiddleWare Application - Act as a interceptor to read admin response and manages communication between various
Bots.

This section will help you to setup Environment for OnBot. Browse various categories provided below:

Expand
titleHardware Configuration 

Kubernetes Master & Node configuration
No. of instances 4 (1 – Master & Bot Framework; 3- Nodes) AWS Instance type m3.xlarge
OS Ubuntu 16.04 Xenial (64bit) Storage 100 GB
Mem (GiB) 16GB
vCPU 4
Software configuration
Kubernetes version: 1.7.3
Docker version Required: 1.12.6
Npm Version: 3.5.2
Node Version: 4.2.6
Elasticsearch Version: 5.4.1

...

Expand
titleInstallation of Kubernetes Cluster

Step 1: Installing kubelet and kubeadm on your hosts(to be followed in both Master and Slave)

  1. apt-get update && apt-get install -y apt-transport-https
  2. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  3. cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
  4. deb http://apt.kubernetes.io/ kubernetes-xenial main EOF
  5. apt-get update
  6. apt-get install docker.io
  7. apt-get install -y kubelet kubeadm kubectl kubernetes-cni
Tip

apt-get install for kubernete utilities(kubeadm,kubectl,kubelet,kubernetes-cni) without specifying version will take the latest version. To Install a specific version refer the following example commands:
apt-get install -y kubeadm=1.6.4-00 kubectl=1.6.4-00 kubelet=1.6.4-00 kubernetes-cni

apt-get install -y kubeadm=1.7.3-01 kubectl=1.7.3-01 kubelet=1.7.3-01 kubernetes-cni


Panel
titleCheck available Versions:

curl -sL https://apt.kubernetes.io/dists/kubernetes-xenial/main/binary-amd64/Packages | grep -E 'Package|Version'

Step 2: Initializing the master (Below Commands applicable only for master)

To initialize the master, pick one of the machines you previously installed kubeadm on, and run:

1. # kubeadm init
In case, kubernetes cluster configuration located in $HOME/.kube/config then run the following command
To start using your cluster, you need to run (as a regular user):
  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

Note

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 commands:
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

Note
iconfalse

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. 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.

Run the following commands: -

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

Note
iconfalse

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.

3. 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 -U'ser "system:serviceaccount:default:default" cannot list pods in the namespace "default"'

    1. kubectl create clusterrolebinding serviceaccounts-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccounts
    2. kubectl create rolebinding bob-admin-binding --clusterrole=admin --user=system:anonymous --namespace=default

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

Above token helps slave to join master node. Token should run in all slaves once step 3 completes.

Master Isolation:

By default, your cluster will not schedule pods on the master for security reasons. If you want to be able to schedule pods on the master, e.g. a single-machine Kubernetes cluster for development, run:

This will remove the node-role.kubernetes.io/master taint from any nodes that have it, including the master node, meaning that the scheduler will then be able to schedule pods everywhere

Step 3: Installing a pod network(Below Commands applicable only for master)

You must install a pod network add-on so that your pods can communicate with each other.

go to addon hyperlink and get weave.net

    kubectl apply -f https://git.io/weave-kube-1.6

Step 4: Adding Slaves to Master node(Below Commands applicable only for slaves)

Run the obtained token given below from Step 2 in all slave nodes not needed to run in add-on server:

    kubeadm join --token <token id> <Primary IP>:6443
1. Post execution, go to the Master machine and run"kubectl get nodes", and verify if the nodes have joined the cluster.
2. Verify if all pods are up and running.
     #kubectl get pods --all-namespaces

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

...

Expand
titleNodeservices setup

Install npm and nodejs by executing the following commands:
1. apt-get install npm
2. apt-get install nodejs

Note

The recommended versions for node and npm are Node 8.x.x and npm5.x.x. If you are getting lower versions using apt-get install, remove existing node setup from your machine and then run the following:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get install nodejs

Now, create a symbolic link between node and nodejs to fix any naming conflicts:

3. sudo ln -s /usr/bin/
nodejs
/usr/bin/node


Clone OnBots from github
1. git clone of chatops respository (git clone –b master https://github.com/CognizantOneDevOps/OnBot.git)
2. Copy $HOME/admin.conf file generated by installing kuberentes inside masterbot folder
3. Update Configurations in OnBots/frameworkservices/masterbot/app/config/config.json
Configuration settings

Panel
borderColorgreen
titleConfiguration


NodeServices config file

location

Description

config.json

app/config/config.json

config.json template is available. Update your environment specific values which are required to start NodeServices

To enable approval flow for mattermost adapter

set "APPROVAL_APP_URL=http://middleware-ip:port/approval" in config.json

certificate.pem , key.pem

must be placed in root of the project which is parallel to app.js

Generate certificate and private key pem files. Used to start the service as httpsServer. pem files are not needed for httpServer. This can be changed in app.js

admin.conf

must be placed in root of the project which is parallel to app.js

It can be found in kubernets master node instance. Path: /home/ubuntu/admin.conf or /etc/kubernetes/admin.conf

ubuntu.yaml

app/config/ubuntu.yaml which is parallel to config.json

Sample file already available. To create bots containers of kind “pod”



Map your configuration in config.json file from app/config directory:

ElasticSearch : elasticsearch url
Kubernetes_End_Point : Kubernetes url
MongoDB : mongodb Host
MONITOR_INTERVAL : Time Interval for monitoring bot
MONITOR_RETENSION : mapped to 1 (stores a jsonobj in elasticsearch which has all hubot metrics of a current second)
MONGO_DB_URL : mongodb database name for approval process of bot actions
MONGO_COLL : mongodb collection name for approval process of bot actions
MONGO_COUNTER : mongodb collection name for storing the number of next ticket to be generated
MONGO_TICKETIDGEN : stores the Id of the collection referred by MONGO_COUNTER

APPROVAL_APP_URL: middleware application endpoint which will handle approval flow in mattermost

MONGO_DB_NAME: The database name which has MONGO_COLL and MONGO_COUNTER in it

Certificate_Path: Path to certificate.pem file
PrivateKey_path: Path to key.pem file
https_port: The port number where OnBots will run if started with https
http_port: The port number where OnBots will run if started with http
botCollections: The array of collections that are used by OnBots (["BotStore","Bots","users","MyBots","BotCategory"])

dbName: The mongodb database name which contains botCollections
exposeIP: The IP to which kubernetes services will be exposed (For bots operating with mattermost)

Scripts/ControllerDescription
deploybot.jsUsed to add/delete/stop the bot
elasticApi.jsConnects to elasticsearch to fetch the metrics , hitmiss ratio and chatlogs of a bot
hubotscripts.jsConstruct shell scripts to start/stop/restart bot. Also, copying the workflow.json into container after edit.
kubectlapi.jsPerforms all container specific actions like create container, get logs from container, copying scripts into container, execute bot start/restart scripts in container,. using the Kubernetes.
routes.jsmongodb query executions to add bot info as document, fetch document, update document and appending new values to a document.


Run Application
1. Install npm modules by running the following from Bots folder
    npm install
2. Run application
    nodejs app
This will run application in specified port

...