quinta-feira, 29 de setembro de 2022

Cloud Engineering & Architecture - Install Docker-compose & Kong for API Management (Instalando o Docker-compose e o Kong para gerenciamento de APIs)

====================
EN
====================
Hello all...
 
Yesterday for my MBA API Management class, I have needed use the Docker and Kong for a Hands-On.

If you don't know, the Kong is a API Gateway and it's one of many Open Source tools for API management.

We have had a Hands-On using Konga that it's an administration UI fot Kong API Gateway. On Konga, we have defined the API source, routes and everything that we needed for call 3 simples APIs.

For this, I have configured an EC2 Instance running Red Hat 8 on AWS Free Tier.

The step-by-step to Docker-compose and Kong installation are bellow, if it helps.

But remember:
1) This worked for me, but might not work for you.
2) This installation is just for academic learn. The real world can be a little bit different.

===================
PTB
===================
Fala pessoal, beleza?

Ontem para uma das aulas de Grenciamento de APIs do MBA, precisei subir o Docker e o Kong para um dos Hands-on.

Para quem não conhece, o Kong é um Gateway API e é uma das várias ferramentas para gerenciamento de APIs open source disponíveis no mercado.

Fizemos o Hands-on através do Konga que é uma UI para administrar o Kong API Gateway. Lá definimos o source, rotas e tudo mais que precisamos para chamar 3 simples APIs.

Para isso, subi uma EC2 instance no Free Tier da AWS rodando Red Hat 8.                

Os passos para instalação do Docker-compose e do Kong estão abaixo, caso ajude alguém.

Lembrando sempre que:
1) O que funcionou para mim pode não funcionar para você.
2) Essa instalação é para fins acadêmicos somente.

====================================
-- Docker-compose Install
====================================
[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo yum update

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo dnf repolist -v

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo dnf install --nobest docker-ce --allowerasing

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo dnf install docker-ce

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo systemctl enable --now docker

[ec2-user@ip-xxx-xx-xx-xxx ~]$ systemctl is-active docker

[ec2-user@ip-xxx-xx-xx-xxx ~]$ curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o docker-compose

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo mv docker-compose /usr/local/bin && sudo chmod +x /usr/local/bin/docker-compose

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

[ec2-user@ip-xxx-xx-xx-xxx ~]$ docker-compose -v
docker-compose version 1.23.2, build 1110ad01

Even with everything apparently OK, when I called the APIs, it gave me the error bellow:

[ec2-user@ip-xxx-xx-xx-xxx ~] docker-compose -f docker-compose-deps.yml up -d
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

I corrected by following the procedure below:

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ sudo docker version
Client: Docker Engine - Community
Version:           20.10.18
API version:       1.41
Go version:        go1.18.6
Git commit:        b40c2f6
Built:             Thu Sep  8 23:11:56 2022
OS/Arch:           linux/amd64
Context:           default
Experimental:      true

Server: Docker Engine - Community
Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:10:04 2022
  OS/Arch:          linux/amd64
  Experimental:     false
containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ docker-compose --version
docker-compose version 1.23.2, build 1110ad01

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ ps aux | grep docker
root       60800  0.6  7.6 1283712 63108 ?       Ssl  02:10   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ec2-user   60923  0.0  0.1 221936  1116 pts/0    R+   02:10   0:00 grep --color=auto docker

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ sudo chown $USER /var/run/docker.sock

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ sudo service docker stop
Redirecting to /bin/systemctl stop docker.service
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ sudo mv /var/lib/docker /var/lib/docker.bak

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ sudo service docker start
Redirecting to /bin/systemctl start docker.service

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ ps aux | grep docker
root       60800  0.6  7.6 1283712 63108 ?       Ssl  02:10   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ec2-user   60923  0.0  0.1 221936  1116 pts/0    R+   02:10   0:00 grep --color=auto docker

====================================
-- Up Kong images
====================================
[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ docker-compose up -d
Creating network "kong-net" with driver "bridge"
Pulling servicea (wesleywillians/kong-service:latest)...
latest: Pulling from wesleywillians/kong-service
6c83e83883df: Pull complete
fe092a9d933b: Pull complete
Pulling serviceb (wesleywillians/kong-service:latest)...
latest: Pulling from wesleywillians/kong-service
Creating apigateway-kong_servicec_1 ... done
Creating apigateway-kong_servicea_1 ... done
Creating apigateway-kong_serviceb_1 ... done

[ec2-user@ip-xxx-xx-xx-xxx apigateway-kong]$ cd docker-kong  

[ec2-user@ip-xxx-xx-xx-xxx docker-kong]$ docker-compose up -d
Creating volume "docker-kong_kong_data" with default driver
Pulling db (postgres:9.5)...
9.5: Pulling from library/postgres
fa1690ae9228: Pull complete
a73f6e07b158: Pull complete
973a0c44ddba: Pull complete
07e5342b01d4: Pull complete
578aad0862c9: Pull complete
a0b157088f7a: Pull complete
6c9046f06fc5: Pull complete
ae19407bdc48: Pull complete
e53b7c20aa96: Pull complete
a135edcc0831: Pull complete
fed07b1b1b94: Pull complete
18d9026fcfbd: Pull complete
4d2d5fae97d9: Pull complete
d419466e642d: Pull complete
Pulling kong (kong:2.3.2-alpine)...
2.3.2-alpine: Pulling from library/kong
e95f33c60a64: Pull complete
dab3768d001d: Pull complete
e24fc8c85ed2: Pull complete
96136c04ffee: Pull complete
Pulling kong-migrations-up (kong:2.3.2-alpine)...
2.3.2-alpine: Pulling from library/kong
Pulling konga-prepare (pantsel/konga:latest)...
latest: Pulling from pantsel/konga
cbdbe7a5bc2a: Pull complete
8f3938f7d3bd: Pull complete
6e3c12f5dc10: Pull complete
ce0cb7a9eeee: Pull complete
a87657869d4f: Pull complete
891b0102e38b: Pull complete
Creating docker-kong_db_1 ... done
Creating konga-prepare                    ... done
Creating docker-kong_kong-migrations_1    ... done
Creating konga                            ... done
Creating docker-kong_kong-migrations-up_1 ... done
Creating docker-kong_kong_1               ... done

====================================
-- List Docker services
====================================
[ec2-user@ip-xxx-xx-xx-xxx docker-kong]$ docker ps

The last steps were to configure the inbound ports on AWS Security panel. 



These links can be help you.
I hope it helps you.

Regards
Mario

Postagem em destaque

[ORACLE] Increasing the number of cores in a virtualized Oracle Database Appliance.

Hello everyone. How are you going? Today, I'll show you the process to increase the number of cores in a virtualized ODA HA X7-2. Import...