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.
We're using this plugin in Kubernetes, thus the configuration guide is Kubernetes oriented.
You are welcome:
This is ~required in Kubernetes, since MaxMind DB size is bigger,
than data size allowed for ConfigMap
or Secret
resource.
Assuming you want to try free GeoLite2 database, that is already downloaded locally.
Create custom Dockerfile
FROM traefik:2.4.9
COPY GeoLite2-City.mmdb /var/lib/traefikgeoip2/
Build and publish to a Docker registry
export TDR=${...}docker build -t ${TDR}/traefik:2.4.9 .docker push ${TDR}/traefik:2.4.9
We recommend to use official Helm chart for installing Traefik into Kubernetes cluster.
Below, there's an instruction for adjusting official Helm chart to install the plugin.
Create a file named traefik.yaml
, replacing ${TDR}
with actual Docker registry path.
image:name: ${TDR}/traefiktag: "2.4.9"pilot:enabled: truetoken: "${TRAEFIK_PILOT_TOKEN}"additionalArguments:- "--experimental.plugins.geoip2.modulename=github.com/traefik-plugins/traefikgeoip2"- "--experimental.plugins.geoip2.version=v0.1.1"
Install customized Traefik Helm chart.
helm repo add traefik https://helm.traefik.io/traefikhelm repo updatehelm upgrade --install -n traefik --create-namespace \my-traefik traefik/traefik --version 10.1.1 -f ./traefik.yaml
Create a file named mw.yaml
apiVersion: traefik.containo.us/v1alpha1kind: Middlewaremetadata:name: geoip2namespace: traefikspec:plugin:geoip:dbPath: "/var/lib/geoip2/GeoLite2-City.mmdb"
Apply
kubectl apply -f mw.yaml
!!! warning TO BE DEFINED
To run linter and tests execute this command
make preparemake