Simple Microservices environment for Developers by DevOps
Hamza Althunibat
DevSecOps Architect | Platform Engineering | Cloud Native | Kubernetes Operators
One of the challenges developers are face is having a workable environment for Microservices in the simplest form, they can easily bring it up, and test various scenarios, even what they think it is a complex setup.
So, when we say simplest form what does it actually mean?
- It depends only on docker, docker-compose, and docker-machine
- One command makes it up.
- Have concepts of service registration and discovery.
- Gateway, with load balancing and rich routing rules by path and host header.
- Can scale services into multiple instances
I think you already got it, the magic needs "doocker-compose" yaml file, and "docker-machine", on my mac machine, I use VMware fusion (can be Virtualbox) and docker machine to build my docker environment, and by using brew docker package I get the client cli that connects to docker machine environment without the overhead of having complete "Docker for Mac" package. It worth mentioning that I use rancher os inside docker machine, here, you can find all the details to run it. once the docker-machine is up, we need to get the machine ip.
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
demo * vmwarefusion Running tcp://192.168.251.128:2376 v18.06.3-ce
let's have a look into docker compose file:
version: '3.4'
services:
whoami:
image: emilevauge/whoami
environment:
- SERVICE_TAGS=traefik.enable=true,traefik.frontend.entryPoints=http,traefik.frontend.rule=Host:whoami.consul.local
- SERVICE_CHECK_HTTP=/
- SERVICE_CHECK_INTERVAL=5s
- TZ=Asia/Dubai
ports:
- target: 80
protocol: tcp
mode: host
depends_on: ["consul","registrator","gateway"]
registrator:
image: gliderlabs/registrator:latest
network_mode: host
volumes:
- /var/run/docker.sock:/tmp/docker.sock
command: -ip=192.168.251.128 -deregister="always" -cleanup=true consul://192.168.251.128:8500
depends_on: ["consul"]
consul:
image: consul:latest
network_mode: host
command: agent -server -bind=192.168.251.128 -bootstrap -client=0.0.0.0 -ui
gateway:
image: traefik:alpine
ports:
- "80:80"
- "8080:8080"
command: ["--accesslog", "--api", "--consul", "--consul.endpoint=192.168.251.128:8500", "--consulCatalog", "--consulCatalog.endpoint=192.168.251.128:8500", "--consulCatalog.exposedByDefault=false", "--consulCatalog.domain=consul.local"]
depends_on: ["consul"]
I use this mechanism inside my CI pipeline for integration testing, you can't imagine what you can achieve using these tools.
Senior Manager, Tech & Digital @PwC | Solutions Architect | Software Development | Cloud, On-Prem & Hybrid Solutions
5 年great read, and easy to follow, didn't deploy?consul before. It will be a great opportunity to try.?
Software Architect | Golang | K8s | DevOps | Typescript
5 年Nice and clean ??