muchlearning / kubernetes-haproxy

auto-updating configuration for HAProxy proxying Kubernetes pods
27 stars 2 forks source link

Dynamic HAProxy for Kubernetes

by MuchLearning

Updates HAProxy's config based on Kubernetes pod changes.

Introduction

This pod watches Kubernetes (or more specifically, the etcd2 used by Kubernetes) for configuration changes and pod changes (creates, deletes). When a change is detected, the configuration is updated, and HAProxy is gracefully reloaded if needed. It uses etcd2's watch feature rather than polling, so updates should be near-instantaneous.

Important Note

Previous versions pulled the configuration from etcd, but this failed when Kubernetes used etcd3. This version now pulls the configuration from the Kubernetes server instead, but will require changes to the configuration. In particular, the K8SBASE environment variable needs to be set, pointing to the URL of the Kubernetes API server.

Configuration

Environment variables

ConfigMaps and Secrets

The HAProxy configuration is driven by some Kubernetes configmaps and secrets in the lb namespace. The pod watches these and updates the configuration when they change.

Examples

The examples directory has various examples for the configuration template.