tiredofit / docker-traefik-cloudflare-companion

Automatically Create CNAME records for containers served by Traefik

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No CNAME's records added

Blood13 opened this issue · comments

Hello :)
Docker swarm + dtcc 6.0.1

[INFO] ** [zabbix] Starting Zabbix Agent
zabbix_agentd [743]: Warning: EnableRemoteCommands parameter is deprecated, use AllowKey=system.run[*] or DenyKey=system.run[*] instead
Starting Zabbix Agent [alpine]. Zabbix 5.0.2 (revision {ZABBIX_REVISION}).
Press Ctrl+C to exit.


[debug] Swarm Mode: true
[debug] Refresh Entries: false
[debug] Traefik Version: 1
[debug] Default TTL: 1

Nothing happens.

environment:
      TRAEFIK_VERSION: 1
      CF_EMAIL: email
      CF_TOKEN: token
      DOMAIN1: domain
      DOMAIN1_ZONE_ID: zoneId
      DOMAIN1_PROXIED: "true"
      TARGET_DOMAIN: target
      SWARM_MODE: "true"
      REFRESH_ENTRIES: "false"
      CONTAINER_LOG_LEVEL: DEBUG

Also it would be nice if script will listen docker sock for not just "start" event, but for "update" (if it possible) too, because docker stack deploy trigger "update" (Updating service ...) if service already exist.

Please try with uppercase variables? (true = TRUE / false = FALSE)
I can certainly look into the update trigger.
The Zabbix warning I will solve in the base image in a few days..

Doesn't help

Press Ctrl+C to exit.


[debug] Swarm Mode: TRUE
[debug] Refresh Entries: FALSE
[debug] Traefik Version: 1
[debug] Default TTL: 1

Thanks. Let me look into - Might want to stick with 5.0.0 for time being until I get this sorted.

Sure, no problem.

I'm having a look at this now, and not seeing the same results you are. You are probably much more advanced with your swarm knowledge than I am, this is how I am doing it.

docker service create --replicas 1 --container-label traefik.enable=true --container-label traefik.http.routers.hello-world.rule=Host\(\foo.example.ca`) --name helloworld alpine ping docker.com
`

Image output:

Found Container: e0ecda48a22f5bdd5eab89ce1c590d8caceef8685a9624d25f788c50b372cdae with Hostname foo.example.ca
Created new record: foo.example.ca to point to home.example.ca

docker inspect helloworld: (only the stuff that matters)

        "Spec": {
            "Name": "helloworld",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "alpine:latest@sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321",
                    "Labels": {
                        "traefik.enable": "true",
                        "traefik.http.routers.hello-world.rule": "Host(`foo.example.ca`)"
                    },
                    "Args": [
                        "ping",
                        "docker.com"
                    ],

Wow, I spent a considerable amount of time trying to unpack what the heck Swarm is doing.

I've added to the tiredofit/traefik-cloudflare-companion:develop image the following:

  • Update Event Support
  • A different way of going about doing Swarm lookups
  • Waaaay more debugging info to tell where the heck things are going on.

Would you be able to give this a test and let me know if we're in good shape now?

I might be able to help.

I'm having the same issue with docker swarm (cloudflare companion not detecting the Hosts).

Having a look at the code in install/usr/sbin/cloudflare-companion line 148 (and 149) in check_service_t2 it uses:

s.attrs.get(u'Spec').get(u'TaskTemplate').get(u'ContainerSpec').get(u'Labels')

It's looking at the container for the label.

When you use Traefik with Docker Swarm you define the labels on the service:
https://doc.traefik.io/traefik/providers/docker/#configuration-examples

version: "3"
services:
  my-container:
    deploy:
      labels:
        - traefik.http.routers.my-container.rule=Host(`example.com`)
        - traefik.http.services.my-container-service.loadbalancer.server.port=8080

These labels then get applied to the service not the container.

So, it should probably be:

s.attrs.get(u'Spec').get(u'Labels')

Hi Drevan, Thanks - I'm seeing different results on my own end for Swarm services, which now based on your log info it seems there are now 3 ways that swarm is reporting which is challenging to say the least. The first one I believe we found out due to someone using Portainer, my way was straight from the command line, can you share how you regularly work with your services?

Hi @tiredofit,

I use a docker-compose.yml file and docker stack deploy -c docker-compose.yml.

I don't think the command line (As you used above)

docker service create --replicas 1 --container-label traefik.enable=true --container-label traefik.http.routers.hello-world.rule=Host(`foo.example.ca`) --name helloworld alpine ping docker.com

Is valid for traefik when in swarm mode.
From the traefik docs:

While in Swarm Mode, Traefik uses labels found on services, not on individual containers.
Therefore, if you use a compose file with Swarm Mode, labels should be defined in the deploy part of your service.
This behavior is only enabled for docker-compose version 3+ (Compose file reference).

So when cloudflare companion has SWARM_MODE=TRUE it should be looking at the services labels and not the containers labels.

Here's a correct (imo) command line equivalent of above:

docker service create --replicas 1 --label traefik.enable=true --label traefik.http.routers.hello-world.rule=Host(`foo.example.ca`) --name helloworld alpine ping docker.com

Notice --label and not --container-label.

Hmm, I'd be curious as to why portainer does it differently to docker swarm, it should apply the labels to the service as well.

Actually - I think Portainer does it how you have listed it with the Spec: Label: - I believe my command (as you identified) is wrong with my crash course in setting up swarm. This is probably why version 5.x of the image worked (Was using just Spec:,Labels:) and 6.xx went all sideways when I thought I knew what I was doing. Thanks for the explanation. I'll review your PR early tomorrow morning and will make adjustments this can work once and for all 👍

Merged and tagged as tiredofit/traefik-cloudflare-companion:6.1.3 - May this finally put this to rest :)