HaProxy has the Loadbalancer for spring boot application - spring-boot

i have configured haproxy as the load balancer for two containerised spring boot application
Below is the sample docker compose file configuration
version: '3.3'
services:
wechat-1:
image: xxxxxx/wechat-social-connector:2.0.0
container_name: wechat-1
ports:
- 81:8000
networks:
- web
#depends_on:
#- wechat-2
wechat-2:
image: xxxxxxxxx/wechat-social-connector:2.0.0
container_name: wechat-2
ports:
- 82:8000
networks:
- web
haproxy:
build: ./haproxy
container_name: haproxy
ports:
- 80:80
networks:
- web
#depends_on:
#- wechat-1
networks:
web:
Docker file
FROM haproxy:2.1.4
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
HA Configuration file
global
debug
daemon
maxconn 2000
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
backend servers
mode http
option httpchk
balance roundrobin
server wechat-1 wechat-1:81 check
server wechat-2 wechat-2:82 check
when i am trying to access my endpoints using the port number 80 i always getting the service unavailable.
After debugging from the haproxy logs noticed the below error
Creating haproxy ... done
Creating wechat-2 ... done
Creating wechat-1 ... done
Attaching to wechat-2, wechat-1, haproxy
haproxy | Available polling systems :
haproxy | epoll : pref=300, test result OK
haproxy | poll : pref=200, test result OK
haproxy | select : pref=150, test result FAILED
haproxy | Total: 3 (2 usable), will use epoll.
haproxy |
haproxy | Available filters :
haproxy | [SPOE] spoe
haproxy | [CACHE] cache
haproxy | [FCGI] fcgi-app
haproxy | [TRACE] trace
haproxy | [COMP] compression
haproxy | Using epoll() as the polling mechanism.
haproxy | [NOTICE] 144/185524 (1) : New worker #1 (8) forked
haproxy | [WARNING] 144/185524 (8) : Server servers/wechat-1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy | [WARNING] 144/185525 (8) : Server servers/wechat-2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy | [ALERT] 144/185525 (8) : backend 'servers' has no server available!
from the logs i understand when haproxy is not able to connect the other two containers which are running perfectly with out any issues.
i tired to use the depends_on attribute(commented for time being) still the issue same .
Can some one help me in fixing this issue?

Please try the below configuration. Few changes in the haproxy.cfg
docker-compose.yaml
version: '3.3'
services:
wechat-1:
image: nginx
container_name: wechat-1
ports:
- 81:80
networks:
- web
depends_on:
- wechat-2
wechat-2:
image: nginx
container_name: wechat-2
ports:
- 82:80
networks:
- web
haproxy:
build: ./haproxy
container_name: haproxy
ports:
- 80:80
networks:
- web
depends_on:
- wechat-1
networks:
web:
Dockerfile
FROM haproxy
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
haproxy.cfg
global
debug
daemon
maxconn 2000
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
backend servers
mode http
option forwardfor
balance roundrobin
server wechat-1 wechat-1:80 check
server wechat-2 wechat-2:80 check
Logs of HAPROXY
Attaching to wechat-2, wechat-1, haproxy
haproxy | Using epoll() as the polling mechanism.
haproxy | Available polling systems :
haproxy | epoll : pref=300, test result OK
haproxy | poll : pref=200, test result OK
haproxy | select : pref=150, test result FAILED
haproxy | Total: 3 (2 usable), will use epoll.
haproxy |
haproxy | Available filters :
haproxy | [SPOE] spoe
haproxy | [CACHE] cache
haproxy | [FCGI] fcgi-app
haproxy | [TRACE] trace
haproxy | [COMP] compression
haproxy | [NOTICE] 144/204217 (1) : New worker #1 (6) forked

Related

Docker: Ports are not available: exposing port TCP 0.0.0.0:61615 -> 0.0.0.0:0: listen tcp 0.0.0.0:61615

I am trying to use ActiveMQ in Docker, but I've started to get this error when starting the container.
Error invoking remote method 'docker-start-container': Error: (HTTP code 500) server error - Ports are not available: exposing port TCP 0.0.0.0:61613 -> 0.0.0.0:0: listen tcp 0.0.0.0:61613: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
I could not find any service that is using these ports (maybe I looking in a wrong way).
I'm seeing that people generally suggest to restart winnat, but I am not sure if it's a good idea and I'd like to know if there are any other solutions to this problem.
Also changing ports ranges won't work in my case since they are already set to a suggested value:
Protocol tcp Dynamic Port Range
---------------------------------
Start Port : 49152
Number of Ports : 16384
Here is a part of my docker-compose file:
version: '3.5'
networks:
test-net:
ipam:
driver: default
config:
- subnet: 172.33.1.0/24
services:
activemq:
image: privat_artifactory
container_name: test-activemq
restart: always
networks:
- test-net
ports:
- "8161:8161"
- "1883:1883"
- "5672:5672"
- "61613-61616:61613-61616"

Error Connecting to server(111): Connection refused when using RabbitMQ in Laravel

I have 2 services written in Laravel. I'm trying to develop my projects with Docker Compose.
one of my services has the below configuration for rabbitMQ in the docker-compose.yml file:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'product_rabbitmq'
ports:
- 5672:5672
- 15672:15672
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=root
- RABBITMQ_DEFAULT_PASS=password
for the second service, I can't use the same port, so I'm changing the port to 5671 or 4000 as the below:
ports:
- 5671:5672
- 15673:15672
But I'm getting the Error Connecting to server(111): Connection refused error.
everything is OK when I shut down the service1 and expose rabbitMQ on port 5672.
also, I have changed my .env file.
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5671
RABBITMQ_USER=root
RABBITMQ_PASSWORD=password
Should I choose another port?

Airflow doesn't work on localhost

I have tried to start Apache Airflow UI on my local machine (Windows 11) but have failed so far. Here are the list of works that I have done so far.
The contents of the 'docker-compose-LocalExecutor.yml' file are as follows:
version: '3.7'
services:
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=airflow
- POSTGRES_PASSWORD=airflow
- POSTGRES_DB=airflow
logging:
options:
max-size: 10m
max-file: "3"
webserver:
image: puckel/docker-airflow:1.10.9
restart: always
depends_on:
- postgres
environment:
- LOAD_EX=n
- EXECUTOR=Local
logging:
options:
max-size: 10m
max-file: "3"
volumes:
- ./dags:/usr/local/airflow/dags
# - ./plugins:/usr/local/airflow/plugins
ports:
- "8080:8080"
command: webserver
healthcheck:
test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
interval: 30s
timeout: 30s
retries: 3
redis:
image: redis
Compose Airflow container:
> cd C:\docker-airflow-master
> docker-compose -f docker-compose-LocalExecutor.yml up -d
Container docker-airflow-master-redis-1 Created
Container docker-airflow-master-postgres-1 Created
Container docker-airflow-master-webserver-1 Running
Container docker-airflow-master-redis-1 Starting
Container docker-airflow-master-postgres-1 Starting
Container docker-airflow-master-redis-1 Started
Container docker-airflow-master-postgres-1 Started
Check which containers are up and running:
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74ac4cd4fafb puckel/docker-airflow:1.10.9 "/entrypoint.sh webs…" 2 days ago Up 40 minutes (healthy) 5555/tcp, 8793/tcp, 0.0.0.0:8080->8080/tcp docker-airflow-master-webserver-1
1acef40c382a postgres:9.6 "docker-entrypoint.s…" 2 days ago Up 3 minutes 5432/tcp docker-airflow-master-postgres-1
e7adfadd1c38 redis "docker-entrypoint.s…" 2 days ago Up 3
minutes 6379/tcp docker-airflow-master-redis-1
Check network connections:
> netstat
Proto Local Address Foreign Address State
TCP [::1]:8080 LAPTOP-0FSNTPS1:63790 TIME_WAIT
TCP [::1]:8080 LAPTOP-0FSNTPS1:63791 TIME_WAIT
TCP [::1]:8080 LAPTOP-0FSNTPS1:63792 TIME_WAIT
Open browser on address localhost:8080:
What could be wrong that it doesn't work?
Have you tried with the latest official docker compose file? It worked fine for me.

Windows10 docker: Grafana not able to access influxdb-502 Bad Gateway

I have installed two containers(influxdb and grafana) inside docker.
Two containers up and running. Able to access grafana(http://localhost:3000/datasources/edit/1/) and influxdb(http://localhost:8086/query?q=show%20databases) urls from browser.
But when we configure influxdb in grafana, grafana api throwing 502: Bad Gateway.
Grafana log message
t=2020-12-23T23:53:36+0000 lvl=eror msg="Data proxy error" logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy/1/query remote_addr=xxx.xx.x.x referer=http://localhost:3000/datasources/edit/1/ error="http: proxy error: dial tcp localhost:8086: connect: connection refused"
t=2020-12-23T23:53:36+0000 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/api/datasources/proxy/1/query status=502 remote_addr=1xxx.xx.x.x time_ms=26 size=0 referer=http://localhost:3000/datasources/edit/1/
Docker Compose file:
version: “2”
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
3000:3000
volumes:
grafana_storage:/var/lib/grafana_storage
networks:
ranga_docker_network
influxdb:
image: influxdb
container_name: influxdb
restart: always
ports:
8086:8086
volumes:
influxdb_storage:/var/lib/influxdb_storage
networks:
ranga_docker_network
environment:
INFLUXDB_DB=telegraf
INFLUXDB_USER=telegraf
INFLUXDB_ADMIN_ENABLED=true
INFLUXDB_ADMIN_USER=admin
INFLUXDB_ADMIN_PASSWORD=telegraf1234
networks:
ranga_docker_network:
volumes:
grafana_storage:
influxdb_storage:
Docker network also up and running.
C:\WINDOWS\system32>docker network ls
NETWORK ID NAME DRIVER SCOPE
f42bea59b834 bridge bridge local
5ae575311d19 host host local
d7f57802a04c monitoring_default bridge local
2419751561dd monitoring_monitoring bridge local
4829f3a73843 monitoring_ranga_docker_network bridge local
4962bd901e12 none null local
ad245f671c22 ranga_docker_network bridge local
Thanks,
Ranga Rao
Issue Root cause: Connect VPN but didn't restart Docker daemon.
Resolution: Restart Docker daemon after connecting VPN.

traefik proxy for docker container running in host network

i am running traefik as a proxy in docker container
i am using DockerToolBox in windows 10
the traefik proxy was able to recognize the service app which is running in 127.0.0.1, but the service app is actually running in docker host = 192.168.99.x ip
version: '3'
services:
reverse_proxy:
image: traefik
command: --api --docker
ports:
- "81:80"
- "8081:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- backend
whoami:
image: containous/whoami
labels:
- "traefik.frontend.rule=Host:whoami.default"
- "traefik.enable=true"
- "traefik.port=80"
network_mode: host
networks:
backend:
driver: bridge
in the Traefik dashboard http://192.168.99.100:8081
it shows http://127.0.0.1:80 for whoami service
instead of http://192.168.99.100:80
any help would be appreciated.
i want network_mode: host to pick 192.168.99.100 instead of 127.0.0.1
As traefik official documentation says, when resolving service IP, first it
try a lookup of host.docker.internal
and second
if the lookup was unsuccessful, fall back to 127.0.0.1
This means we can just add a host in the traefik container, using --add-host {docker0_IP}(it's the bridge's IP, you can easily use docker inspect {NAME_OF_TRAEFIK} and find the IP of Gateway(for me, it's 172.18.0.1). If you use docker-compose, you can use add following lines to your definition of traefik:
extra_hosts:
- host.docker.internal:{docker0_IP}
Also, I find that it's ok to use the IP my eth0 IP, which means the IP of your LAN(for me, it's 192.168.0.20).
Then, recreate traefik and everything works like a daisy.

Resources