Traefik plugin that registers a custom middleware for getting data from MaxMind GeoIP databases and pass it downstream via HTTP request headers.
Supports both GeoIP2 and GeoLite2 databases.
The tricky part of installing this plugin into containerized environments, like Kubernetes, is that a container should contain a database within it.
Warning
Setup below is provided for demonstration purpose and should not be used on production. Traefik's plugin site is observed to be frequently unavailable, so plugin download may fail on pod restart.
Tested with official Traefik chart version 26.0.0.
The following snippet should be added to values.yaml
:
experimental:
plugins:
geoip2:
moduleName: github.com/traefik-plugins/traefikgeoip2
version: v0.22.0
deployment:
additionalVolumes:
- name: geoip2
emptyDir: {}
initContainers:
- name: download
image: alpine
volumeMounts:
- name: geoip2
mountPath: /tmp/geoip2
command:
- "/bin/sh"
- "-ce"
- |
wget -P /tmp https://raw.githubusercontent.com/traefik-plugins/traefikgeoip2/main/geolite2.tgz
tar --directory /tmp/geoip2 -xvzf /tmp/geolite2.tgz
additionalVolumeMounts:
- name: geoip2
mountPath: /geoip2
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: geoip2
namespace: traefik
spec:
plugin:
geoip2:
dbPath: "/geoip2/GeoLite2-City.mmdb"
The plugin currently supports the following configuration settings:
Name | Description |
---|---|
DbPath | Required Container path to GeoIP database. |
PreferXForwardedForHeader | Should X-Forwarded-For header be used to extract IP address. Default false . |
To run linter and tests execute this command
just test