LoadBalance·

Getting Started with the AI Module

This guide explains step by step how to configuration load balancer with Docker Swarm.

Introduction

Logger software stands up with a single container in default installation. If you need to scale the system, you can do it in different ways. In this blog post, I will explain the scaling configuration on Docker Swarm structure using NGINX.

✨ Prerequisites

  • Docker Swarm
  • Docker Engine
  • Docker Compose
  • Nginx

😌 Installation Steps

  1. Install Docker
# Update package list and upgrade packages
sudo apt-get update -y && sudo apt-get upgrade -y
# Install docker
apt install docker.io
# Check docker installation
sudo systemctl status docker
# Enable auto start
sudo systemctl enable docker
  1. Install Docker Compose
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Make it executable
sudo chmod +x /usr/local/bin/docker-compose
# Check docker compose installation
docker-compose --version
  1. Swarm Init and Create Master Node
# Swarm init
sudo docker swarm init --advertise-addr <MASTER_NODE_IP_ADDRESS>
  1. Add Worker Node to Cluster
# Swarm join
sudo docker swarm join --token <TOKEN> <MANAGER_IP>:2377
  1. Create a Compose File
# Install Logger and Nginx
sudo nano docker-compose.yml

Add the following content:

yaml
version: '3.8'
services:
  randomapp:
    image: dolusoft/logger-v1.0
    deploy:
      mode: replicated
      replicas: 20
      placement:
        constraints:
          - node.role == worker
      update_config:
        parallelism: 2
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
        reservations:
          cpus: '0.25'
          memory: 256M

  nginx:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    deploy:
      mode: replicated
      replicas: 2
      placement:
        constraints:
          - node.role == manager
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: any
        delay: 5s

networks:
  app-network:
    driver: overlay
    attachable: true
  1. Create a Nginx Config File
# Config Nginx
sudo nano nginx.conf

Add the following content:

cfg
events {
    worker_connections 4096;
    multi_accept on;
    use epoll;
}

http {
    upstream logger_backend {
        least_conn;
        server logger:3000;
        keepalive 32;
    }

    server {
        listen 80;
        
        location / {
            proxy_pass http://logger_backend;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            
            proxy_connect_timeout 60s;
            proxy_send_timeout 60s;
            proxy_read_timeout 60s;
            
            proxy_buffering on;
            proxy_buffer_size 4k;
            proxy_buffers 8 4k;
        }
        
        location /health {
            access_log off;
            return 200 "healthy\n";
        }
    }
}
  1. Deploy Stack
# Deploy stack
docker stack deploy -c docker-compose.yml logger-stack
  1. List Docker Service
docker service ls
  1. Viewing Running Containers of Logger Service
docker service ps logger-stack_logger
  1. Sending HTTP Request to Nginx from Container for Testing
curl http://[SWARM_IP]
  1. Viewing Service logs
docker service logs logger-stack_logger

Here are some blogs you can read... but there are many others !

Docker On Windows

Display togglable accordion panels.

Docker On Ubuntu

Display images or content in a scrollable area.

Fortigate Syslog Configuration

Add a customizable command palette to your app.

Sophos Syslog Configuration

Display a non-modal dialog that floats around a trigger element.

Load Balance Using Docker Swarm

Display a range field

Enable Web URL Logging on Fortigate

Display data in a table.