Docker Container deployment with multi layers

That is a SJSU lecture course project. You need to deploy a list of service via Docker approach. That is not difficult if just one or two. However, if it is a list of Docker containers with several layers, you will feel headache. Anyway, you need to finish it to avoid score F in the course.

  1. The request deploy diagram

  1. The explanation
  1. )1st layer, the Front End GUI Layer with Node.Js app
  2. )2nd layer, API Gateway to dispatch call to the right service with Kong GateWay
  3. )3rd layer, EC2 ELB Application Layer to distributes application traffic to multiple containers.
  4. )4th layer, the DB layers to store order information

So, you have 4 layers and the action layer is the 3rd layer, all others are auxiliaries. For example, the first layer is to show you the GUI, the 2nd layers to map the 3rd layer API link to a API name with extra authentication feature, and the last layer is to store information.

The Jump Box node in the diagram is allowed you to SSH from local to EC2 server, and manage all other EC2 nodes/containers.

  1. The essential Docker commands

You can refer link https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 to install the Docker in your local/remote Ubuntu host

Here is the commands got it from Prof MakeFile

net-ls:

        docker network ls

net-inspect:

        docker network inspect $(net)

net-create:

        docker network create –driver bridge gumball_front

        docker network create –driver bridge gumball_app

        docker network create –driver bridge gumball_db

net-drop:

        docker network rm gumball_front gumball_app gumball_db gumball_extra

docker-ps:

         docker ps –all –format “table {{.ID}}t{{.Names}}t{{.Image}}t{{.Status}}t”

docker-ps-ports:

         docker ps –all –format “table {{.Names}}t{{.Ports}}t”

compose-up:

        docker-compose up

compose-down:

        docker-compose down         

app-up:

        docker-compose scale coordinator=1 member=3 mysql=1 gumball=1

mysql-up:

        docker-compose scale mysql=1

riak-up:

        docker-compose scale coordinator=1 member=3

riak-up-node1:

        docker-compose scale coordinator=1

nodejs-up:

        docker-compose scale nodejs=1

nodejs-down:

        docker-compose stop nodejs

        docker-compose rm nodejs

gumball-up:

        docker-compose scale gumball=1

gumball-down:

        docker-compose stop gumball

        docker-compose rm gumball

gumball-logs:

        docker logs gumball_gumball_1

kong-up:

        docker-compose scale cassandra=1 kong=1

gumball-shell:

        docker exec -it gumball_gumball_1 bash

        #docker exec -it gumball_gumball_run_1 bash

mysql-shell:

        docker exec -it gumball_mysql_1 bash

cassandra-shell:

        docker exec -it gumball_cassandra_1 bash

kong-shell:

        docker exec -it gumball_kong_1 bash

riak-status:

        docker-compose exec coordinator riak-admin cluster status

  1. The steps

Below is the full setup in the local host, we ignore the setup in the EC2 ELB part.

0) Modify compose.yml in  /home/test/cmpe281/golabs/godata/go-gumball-riak/gumball

 (need to open 3306 as host can access)

  mysql:

    image: mysql:5.5

    ports:

      – 3306:3306

1) Compose mysql, and load data (see above 9. setting in prof file for sql data)

cd /home/test/cmpe281/golabs/godata/go-gumball-riak/gumball

docker-compose up mysql

2).build nodejs

  cd  /home/test/cmpe281/golabs/godata/go-gumball-riak/nodejs-docker

  make docker-build

3).build gumball

        cd /home/test/cmpe281/golabs/godata/go-gumball-riak/gumball-riak

        *a)modify server.go

     

        *b)

                docker-build:

                        docker build -t gumball

        make docker-build

4) build whole environment with composer

       *a)modify composer.yml

         **(must set host ip:192.168.137.203:3306,if user can’t access mysql)

  gumball:

    image: gumball

          gumball:

    image: gumball

networks:

      – app

      – db  

    restart: always

    environment:

      – MYSQL=”root:cmpe281@tcp(192.168.137.203:3306)/cmpe281″

      – RIAK1=http://gumball_member_1:8098

      – RIAK2=http://gumball_member_2:8098

      – RIAK3=http://gumball_member_3:8098  

       

        cd /home/test/cmpe281/golabs/godata/go-gumball-riak/gumball

        make compose-up

5) Scale up to 3 member, if not gumball will fail

cd /home/test/cmpe281/golabs/godata/go-gumball-riak/gumball

make app-up

test@dm1:~/cmpe281/golabs/godata/go-gumball-riak/gumball$ make app-up

6) If you try http://192.168.137.203:8080, it will show the screen, however, if you click button, it will show error (as we are not yet set kong gateway mapping)

nodejs_1       |

nodejs_1       | key:request_path, value:/goapi/gumball

nodejs_1       | key:message, value:API not found with these values

nodejs_1       | key:request_host, value:kong

nodejs_1       | count = undefined

7.)  Setup kong api to build the kong api mapping

*a) check kong is ok

docker exec -it gumball_kong_1 bash

        curl http://localhost:8001

        [root@0aa7c997ce70 /]# curl http://gumball_gumball_1:3000/ping

{

  “Test”: “API version 1.0 alive!”

}

  [root@9cec69c2a21b /]# curl http://localhost:8001

                {“timers”:{“running”:0,”pending”:3},”configuration”:{“serf_log”:”/usr/local/kong/logs/serf.log”,”cassandra_ssl”:false,”nginx_acc_logs”:”/usr/local/kong/logs/access.log”,”cassandra_repl_factor”:1,”cassandra_key

*b) let’s create one mapping

curl -X POST http://localhost:8001/apis

  -d “name=goapi”

  -d “request_path=/goapi”

  -d “upstream_url=http://gumball_gumball_1:3000″

  -d  “strip_request_path=true”

Double check:

[root@0aa7c997ce70 /]# curl http://localhost:8001/apis

{“data”:[{“upstream_url”:”http://gumball_gumball_1:3000″,”strip_request_path”:true,”request_path”:”/goapi”,”id”:”a02c705a-5627-4293-8bb0-15fe7714b01a”,”created_at”:1541028296000,”preserve_host”:false,”name”:”goapi”}],”total”:1}

*8) test whether it works outside the kong container (tested in the browser)

http://192.168.137.203:8080/  -> insertQuarter, Crank, it works!

F:AllHere2014Apr12_2015Nov02personalmomSJSUHomeWork_CMPE281-Clound Systemlab8nodejs_brower_null_ifNotAdd_authenticatedKey.gif






Leave a Reply