Sign inSign up

containeroo/syncflaer

By containeroo

Updated over 3 years ago

Synchronize Traefik host rules with Cloudflare

Image
1

50K+

containeroo/syncflaer repository overview

SyncFlaer

Synchronize Traefik host rules and/or Kubernetes Ingresses with Cloudflare®.

Docker Image Version (latest semver) Docker Pulls GitHub go.mod Go version

Why?

  • Dynamically create, update or delete Cloudflare® DNS records based on Traefik http rules and/or Kubernetes Ingresses (apiVersion: networking.k8s.io/v1)
  • Supports multiple Traefik instances
  • Supports Kubernetes Ingresses (apiVersion: networking.k8s.io/v1)
  • Supports multiple Cloudflare zones
  • Update DNS records when public IP changes
  • Supports configuring additional DNS records for services outside Traefik (i.e. vpn server)

Contents

Usage

Simple

Create a config file based on the example located at configs/config.yml.

syncflaer --config-path /opt/syncflaer.yml

Flags:

  -c, --config-path string   Path to config file (default "config.yml")
  -d, --debug                Enable debug mode
  -v, --version              Print the current version and exit
Kubernetes

You can run SyncFlaer as a Kubernetes CronJob. For an example deployment, please refer to the files located at deployments/kubernetes.

Configuration

Overview

SyncFlaer must be configured via a YAML config file. Some secrets can be configured using environment variables.

Config File

The full configuration file can be found at configs/config.yml.

Using Multiple Traefik Instances

You can configure SyncFlaer to gather host rules from multiple Traefik instances.
The configuration for two instances would look like this:

traefikInstances:
  - name: instance1
    url: https://traefik1.example.com
    user: admin1
    password: supersecure
    customRequestHeaders:
      X-Example-Header: instance1
    ignoredRules:
      - instance1.example.com
  - name: instance2
    url: https://traefik2.example.com
    user: admin2
    password: stillsupersecure
    customRequestHeaders:
      Authorization: env:TREAFIK_AUTH_HEADER
    ignoredRules:
      - instance2.example.com

Every instance can be configured to use different HTTP basic auth, custom request headers and ignored rules.

Kubernetes Ingress Support

SyncFlaer can be configured to support Kubernetes Ingresses. By default, SyncFlaer will sync all Ingresses.

If you run SyncFlaer in a Kubernetes cluster, please refer to the deployments/kubernetes folder for an example deployment.
If you run SyncFlaer outside a Kubernetes cluster, you can use the KUBECONFIG environment variable to configure a specific kubeconfig file.
If the KUBECONFIG environment variable is not set, SyncFlaer will use the default kubeconfig file located at $HOME/.kube/config.

If you want to ignore specific Ingresses, use the annotation syncflaer.containeroo.ch/ignore=true.

To overwrite the default configuration for DNS records, you can specify the following annotations for each Ingress:

AnnotationExample
syncflaer.containeroo.ch/typeA or CNAME
syncflaer.containeroo.ch/contentexample.com
syncflaer.containeroo.ch/proxiedtrue
syncflaer.containeroo.ch/ttl120
Environment Variables

Instead of putting secrets in the config file, SyncFlaer can grab secrets from environment variables.

You can define the names of the environment variables by using the env: prefix.

ConfigurationExample
notifications.slack.webhookURLenv:SLACK_TOKEN
password in traefikInstancesenv:TRAEFIK_K8S_PW
customRequestHeaders in traefikInstancesenv:TRAEFIK_AUTH_HEADER
cloudflare.apiTokenenv:CF_API_TOKEN
Defaults

If not specified, the following defaults apply:

NameDefault Value
ipProviders["https://ifconfig.me/ip", "https://ipecho.net/plain", "https://myip.is/ip", "https://checkip.amazonaws.com", "https://api.ipify.org"]
kubernetes.enabledfalse
managedRootRecordtrue
cloudflare.deleteGrace0 (delete records instantly)
cloudflare.defaults.typeCNAME
cloudflare.defaults.proxiedtrue
cloudflare.defaults.ttl1
notifications.slack.usernameSyncFlaer
notifications.slack.iconURLhttps://www.cloudflare.com/img/cf-facebook-card.png
Additional Records

You can specify additional DNS records which are not configured as Traefik hosts.

Example A Record
KeyExampleDefault ValueRequired
namea.example.comnoneyes
typeAcloudflare.defaults.typeno
proxiedtruecloudflare.defaults.proxiedno
ttl1cloudflare.defaults.ttlno
content1.1.1.1current public IPno
Example CNAME Record
KeyExampleDefault ValueRequired
namevpn.example.comnoneyes
typeCNAMEcloudflare.defaults.typeno
proxiedfalsecloudflare.defaults.proxiedno
ttl120cloudflare.defaults.ttlno
contentmysite.comcloudflare.zoneNameno
Cloudflare API Token

To create an API token visit https://dash.cloudflare.com/profile/api-tokens, click on Create token and select Get started.

Select the following settings:

Permissions:

  • Zone - DNS - Edit

Zone Resources:

  • Include - All Zones

Upgrade Notes

From 4.x to 5.x

The cloudflare.apiToken config is now required to be present in config file.
If you want to use environment variables for Slack webhook URL, Traefik HTTP basic auth password and Cloudflare API token, you have to use the env: prefix. Everything after the env: part will be used as the name of the environment variable.

2022 containeroo

Cloudflare and the Cloudflare logo are registered trademarks owned by Cloudflare Inc. This project is not affiliated with Cloudflare®.

License

GNU GPLv3

Tag summary

Content type

Image

Digest

sha256:be006eff9

Size

21.5 MB

Last updated

over 3 years ago

docker pull containeroo/syncflaer