Hey guys,
I'm trying to use a specific Label at my service definition as part of the URL.
---
apiVersion: v1
kind: Service
metadata:
name: example0
labels:
test: myapp0
spec:
selector:
app: example
ports:
- port: 80
With the defaultRule at the traefik command-CLI
...
- --providers.consulcatalog.defaultRule=Host("{{ regexReplaceAll `([^-].*)\-.*` .Name `$1` }}.{{ index .Labels `test`}}.k8s")
...
I only get example0..k8s.example.com; the value of my customLabel 'test' is missing.
I assume the label is missing in ConsulCatalog too.
How to check this? How to bring the Label from K8s to Consul Catalog?
Hello @Raskosk.
You mention that you are using the Traefik CLI, but how are you using it? Is it in a kubernetes manifest? is it in a helm template?
If you are wanting to use label values on a container, you may want to use the downward API (Expose Pod Information to Containers Through Files | Kubernetes)
As you can see above, I'm using a DaemonSet to deploy traefik.
I'm now trying to implement the default example of Traefik-Documentation according to ConsulCatalog Default Rule. - --providers.consulcatalog.defaultRule=Host("{{ .Name }}.{{ index .Labels
test}}.k8s.example.com")
to get sth like example0.myapp0.k8s.example.com
.
But actually, I'm ending up with a result like example0..k8s.example.com
.
Can you help?
@daniel.tomcej
Any idea's about how to retrieve labels or annotations within the default rule?
Hello @Raskosk
Can you please try the following example as the reference:
providers:
docker:
exposedByDefault: false
consulCatalog:
refreshInterval: "10s"
endpoint:
address: "consul:8500"
scheme: "http"
defaultRule: "Host(`{{ index .Labels \"application_name\" }}.{{ index .Labels \"env\" }}.{{.Name}}`)"
Hey @jakubhajek,
I've just tried this, without any success.
The test-service is:
apiVersion: v1
kind: Service
metadata:
name: example
labels:
test: 'banana'
env: 'dev'
annotations:
'consul.hashicorp.com/service-sync': 'true'
'consul.hashicorp.com/service-meta-test': 'banana'
spec:
selector:
app: example
ports:
- port: 80
The applied defaultRule is
- --defaultRule="Host(`{{ index .Labels \"test\" }}.{{ index .Labels \"env\" }}.{{.Name}}`)"
Ending up with this:
It seems consulCatalog doesn't provide labels to use them in defaultRule...
Do you got any working examples by using labels or annotations?