项目作者: GiGInnovationLabs

项目描述 :
Traefik plugin for MaxMind GeoIP2
高级语言: Go
项目地址: git://github.com/GiGInnovationLabs/traefikgeoip2.git
创建时间: 2021-07-15T12:52:54Z
项目社区:https://github.com/GiGInnovationLabs/traefikgeoip2

开源协议:Apache License 2.0

下载


Traefik plugin for MaxMind GeoIP2

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.

Installation

The tricky part of installing this plugin into containerized environments, like Kubernetes,
is that a container should contain a database within it.

Kubernetes

[!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:

  1. experimental:
  2. plugins:
  3. geoip2:
  4. moduleName: github.com/traefik-plugins/traefikgeoip2
  5. version: v0.22.0
  6. deployment:
  7. additionalVolumes:
  8. - name: geoip2
  9. emptyDir: {}
  10. initContainers:
  11. - name: download
  12. image: alpine
  13. volumeMounts:
  14. - name: geoip2
  15. mountPath: /tmp/geoip2
  16. command:
  17. - "/bin/sh"
  18. - "-ce"
  19. - |
  20. wget -P /tmp https://raw.githubusercontent.com/traefik-plugins/traefikgeoip2/main/geolite2.tgz
  21. tar --directory /tmp/geoip2 -xvzf /tmp/geolite2.tgz
  22. additionalVolumeMounts:
  23. - name: geoip2
  24. mountPath: /geoip2

Create Traefik Middleware

  1. apiVersion: traefik.io/v1alpha1
  2. kind: Middleware
  3. metadata:
  4. name: geoip2
  5. namespace: traefik
  6. spec:
  7. plugin:
  8. geoip2:
  9. dbPath: "/geoip2/GeoLite2-City.mmdb"

Configuration

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.

Development

To run linter and tests execute this command

  1. just test