XenonStack

A Stack Innovator

Post Top Ad

Monday 18 September 2017


Overview

In this Blog, We will Cover How to Build Slack like Online Chat using Rocket Chat and Deploy on Containers using Docker and Kubernetes.

Before This, We are Using Rocket Chat application on OpenStack Instances on On-Premises Deployment.

So We Migrated our Existing On-Premises Cloud Infrastructure to Containers based on Docker and Kubernetes.

As per official Docker Documentation, Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.

Kubernetes is container orchestration layer on top of container runtime/engine to manage and deploy Containers effectively.


Prerequisites for Rocket Chat Deployment on Kubernetes

For Deployment you need
Kubernetes is for automating deployment, scaling, management, the orchestration of containerized applications. We can use kubernetes cluster or for testing purpose we can also use minikube for Kubernetes.

For Shared Persistent Storage, we are using GlusterFS. GlusterFS is a scalable network file system.

Rocket.Chat is a Web-based Chat Server, developed in JavaScript, using the Meteor full stack framework.

Dockerfile is a text document that contains all the information/commands that what we need to configure any application in the respective container.

The Registry is an online storage for container images and lets you distribute Container images.

We can use any of following Container Registry for storing.

Kubectl is command line tool to manage Kubernetes cluster remotely and you can also configure in your machine follow this link.

Notes - If you are using an official image of Rocket Chat and MongoDB then you can skip Step 1, 2, 3, 4, 5, 6 and move forward to Storage Volume (Step 7).


Step 1 - Create a Rocket Chat Container Custom Image

Create a file name “Dockerfile” for Rockets Chat Container Image.

$ touch Dockerfile

Now Add the Following content to the dockerfile of Rocket Chat application

FROM node:4-slim
MAINTAINER XenonStack
COPY bundle/ /app/
RUN cd /app/programs/server \&& npm install
ENV PORT=3000 \
ROOT_URL=http://localhost:3000
EXPOSE 3000
CMD ["node", "/app/main.js"]

This Rocket Chat Application is based on NodeJS so we need to use NodeJS docker image from docker hub as a base image for Rocket Chat application.

After then we put our custom code of the Rocket Chat application to docker container and install all the required dependencies of rocket chat application to docker container.


Step 2 - Build Rocket Chat Docker Custom Image

$ docker build -t rocketchat:v1.0


Step 3 - Create a MongoDB Container Custom Image

Create a file name “Dockerfile” for MongoDB Container Image in new Folder named MongoDB.

$ mkdir mongodb && cd mongodb

$ touch Dockerfile

Now Add the Following content to the dockerfile of Mongo -
FROM ubuntu
MAINTAINER XenonStack
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list && \
apt-get update && \
apt-get install -y mongodb-org
VOLUME ["/data/db"]
WORKDIR /data
EXPOSE 27017
CMD ["mongod"]

This MongoDB image has a base image of Ubuntu but we can also use official docker image of MongoDB. We have created this dockerfile for MongoDB Version 3.0 for some compatibility reasons with Rocket Chat Application.

Next, we mount Volume “/data/db” for persistent storage of container.

Next, we expose 27017 port for incoming requests to MongoDB server. Then, we start MongoDB server in dforeground mode so that we can see logs in “stdout” of container.


Step 4 - Building a MongoDB Docker Custom Image

$ docker build -t mongo:v3.0


Step 5 - Adding Container Registry to Docker Daemon

If you are using docker registry other than docker hub to store images then you need to add that container registry to your local docker daemon and kubernetes Docker Nodes also.

There are so many ways to add container registry to docker daemon as per different operating systems.

So i will explain one of them which i'm using daily basis.
$ docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:14:09 2017
OS/Arch: linux/amd64 (Ubuntu 16.04)

Now we need to Create a “daemon.json” in below mentioned location

$ sudo nano /etc/docker/daemon.json

And add the following content to it.
{

"insecure-registries": ["<name of your private registry>"]

}

Now Run the following commands to reload systemctl and restart docker daemon.

$ sudo systemctl daemon-reload

$ sudo service docker restart

To verify that your container registry is added to local docker daemon, use the below mentioned steps.

$ docker info

In output of above you get your container registry like this

Insecure Registries:

<your container registry name>

127.0.0.0/8


Step 6 - Pushing Custom PostgreSQL Container Image to Container Registry

Let`s start to uploading our custom images to container registry like

If you have authentication enabled on container registry then you need to login first then we can upload or download images from container registry.

To Login follow below mentioned command

$ docker login <name of your container registry>

Username : xxxx

Password: xxxxx

For AWS ECR you will get registry url, username and password from respective cloud provider when you launch container registry on cloud.

Here is shell script that will add your aws credentials for Amazon ECR.

#!/bin/bash
pip install --upgrade --user awscli
mkdir -p ~/.aws && chmod 755 ~/.aws
cat << EOF > ~/.aws/credentials
[default]
aws_access_key_id = XXXXXX
aws_secret_access_key = XXXXXX
EOF
cat << EOF > ~/.aws/config
[default]
output = json
region = XXXXX
EOF
chmod 600 ~/.aws/credentials
ecr-login=$(aws ecr get-login --region XXXXX)
$ecr-login

Now we need to tag rocketchat images and push them to any of the above mentioned container registry.

To Tag images

$ docker tag rocketchat:v1.0 <name of your registry>/rocketchat:v1.0

$ docker tag mongo:v3.0 <name of your registry>/mongo:v3.0

To Push Images

$ docker push <name of your registry>/rocketchat:v1.0

$ docker push <name of your registry>/mongo:v3.0

Similarly we can push images to any of above mentioned container registry like aws ecr , google container registry or azure container registry etc.


Step 7 - Create a Storage Volume (Using GlusterFS)

Using below mentioned command we create a volume in GlusterFS cluster for MongoDB. As we are using glusterfs as persistent volume to mongodb container so we need to create volume in GlusterFS. We need to add the IP Address or DNS instead of node1 and node2 as you specified in your installation of glusterfs.

$ gluster volume create apt-cacher replica 2 transport tcp k8-master:/mnt/brick1/mongodb-disk k8-1:/mnt/brick1/mongodb-disk
$ gluster volume start mongodb-disk
$ gluster volume info mongodb-disk

deploying rocket chat on kubernetes

Figure - Information of Gluster Volume


Step 8 - Deploy MongoDB on Kubernetes

Deploying MongoDB Single Node on Kubernetes have following prerequisites -
  • Docker Image: We have created a Docker Image for MongoDB in Step 4 and pushed to docker hub or private docker registry.

Continue Reading The Full Article at - XenonStack.com/Blog

No comments:

Post a Comment