peterweissdk/keepalived-db-cluster

By peterweissdk

•Updated about 1 month ago

Docker container running Keepalived and MariaDB Galera cluster state monitoring.

Image
Networking
Monitoring & observability
0

4.9K

peterweissdk/keepalived-db-cluster repository overview

ā šŸ’¾ Keepalived container with Galera check-script

Static Badge Static Badge Static Badge Static Badge

A lightweight, Alpine-based Docker container for running Keepalived with VRRP (Virtual Router Redundancy Protocol) support and MariaDB Galera cluster state monitoring.

šŸ’” This container is a slightly modified version of peterweissdk/keepalived⁠, with an added check script for monitoring the state of a MariaDB Galera cluster. It is designed to be used in conjunction with peterweissdk/galera-compose⁠, which sets up and runs a MariaDB Galera cluster.

⁠✨ Features

  • Alpine-based: Lightweight and secure base image
  • VRRP support: High availability with Virtual Router Redundancy Protocol (VRRP)
  • Easy Configuration: Configure Keepalived using environment variables, and service check-scripts
  • Health Checks: Monitor service health with built-in Docker health checks

ā šŸš€ Quick Start

Run the container:

# Pull the image
docker pull ghcr.io/peterweissdk/keepalived-db-cluster:latest

# Run with custom configuration
docker run -d \
  --name keepalived \
  --restart=unless-stopped \
  --cap-add=NET_ADMIN \
  --cap-add=NET_BROADCAST \
  --cap-add=NET_RAW \
  --net=host \
  --env-file .env \
  keepalived-db-cluster:latest

# Run the container using the provided Docker Compose and .env file
docker compose up -d

ā šŸ”§ Configuration

⁠Environment Variables
VariableDescriptionExample
TZContainer timezoneEurope/Copenhagen
VRRP_INSTANCEVRRP instance nameVI_1
INTERFACENetwork interfaceeth0
STATENode state (MASTER/BACKUP)MASTER
PRIORITYNode priority (1-255)100
ROUTER_IDUnique router ID52
VIRTUAL_IPSVirtual IP address with subnet mask192.168.1.100/24
UNICAST_SRC_IPSource IP for unicast communication192.168.1.101
UNICAST_PEERSPeer IP addresses for unicast communication192.168.1.102
WEIGHTWeight for tracked scripts50
FALLNumber of failures before transition2
RISENumber of successes before transition2
⁠Required Capabilities
  • NET_ADMIN: For network interface configuration
  • NET_BROADCAST: For VRRP advertisements
  • NET_RAW: For raw socket access
⁠Service Check-Script

Create a script to run at regular intervals to check the state of your service. Create a bind mount and copy the script into it

  • Name of script: check-script.sh
  • Bind mount point: /usr/local/scripts/
  • Runs at regular intervals: 2 seconds

ā šŸ—ļø Building from Source

# Clone the repository
git clone https://github.com/peterweissdk/keepalived-db-cluster.git
cd keepalived-db-cluster

# Build the image
docker build -t keepalived-db-cluster:latest .

ā šŸ“ Directory Structure

keepalived-db-cluster/
ā”œā”€ā”€ check-script
│   └── check-script.sh
ā”œā”€ā”€ conf/
│   └── keepalived.conf_tpl
ā”œā”€ā”€ scripts/
│   └── check_and_run.sh
ā”œā”€ā”€ .env
ā”œā”€ā”€ Dockerfile
ā”œā”€ā”€ docker-entrypoint.sh
ā”œā”€ā”€ healthcheck.sh
ā”œā”€ā”€ docker-compose.yml
ā”œā”€ā”€ LICENSE
└── README.md

ā šŸ” Health Check

The container includes a comprehensive health check system that monitors:

  1. Keepalived Process Status

    • Verifies the keepalived daemon is running
  2. Virtual IP environment variable

    • Verifies the VIRTUAL_IPS environment variable is set

View health status:

docker inspect --format='{{.State.Health.Status}}' keepalived-db-cluster

View detailed health check history:

docker inspect --format='{{json .State.Health}}' keepalived-db-cluster | jq

Watch health status in real-time:

watch -n 5 'docker inspect --format="{{.State.Health.Status}}" keepalived-db-cluster'

ā šŸ¤ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

ā šŸ†˜ Support

If you encounter any issues or need support, please file an issue on the GitHub repository.

ā šŸ“„ License

This project is licensed under the GNU GENERAL PUBLIC LICENSE v3.0 - see the LICENSE⁠ file for details.

Tag summary

Content type

Image

Digest

sha256:6644fd041…

Size

266 Bytes

Last updated

about 1 month ago

docker pull peterweissdk/keepalived-db-cluster:sha256-411db8cb7f568484b60d6c37f73bf0a06cb380200c9cef6575f0bb8883ce1dc1.sig