简体   繁体   中英

How to use Traefik IngressRoute on a Headless Service

I am trying to configure a Traefik IngressRoute to point to a Headless service (the service point to a Database behind the cluster). The Setup work well with a "normal" service (with the endpoint inside the cluster). I am using traefik 2.3.

But when I try to create an ingressRoute that point to the headless service, I have that error in the traefik logs:

time="2020-11-27T10:41:53Z" level=error msg="cannot define a port for dev/-central-db-service" ingress=webapp-ingressroute providerName=kubernetescrd namespace=traefik

time="2020-11-27T10:41:54Z" level=error msg="cannot define a port for dev/central-db-service" providerName=kubernetescrd ingress=webapp-ingressroute namespace=traefik

Here is the IngressRoute I am trying to create, along with the Headless service with endpoint:

 --- apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: webapp-ingressroute namespace: traefik labels: spec: entryPoints: - websecure routes: - match: Host(`couchdb.test.io`) kind: Rule services: - name: central-db-service kind: Service port: 5984 namespace: dev tls: secretName: certificate --- kind: Endpoints apiVersion: v1 metadata: name: central-db-service namespace: dev subsets: - addresses: - ip: 192.168.0.50 ports: - port: 5984 name: central-db-service --- kind: Service apiVersion: v1 metadata: name: central-db-service namespace: dev spec: clusterIP: None ports: - port: 5984 targetPort: 5984

The setup work perfectly with a "normal" service.

What did I miss? Is it even possible to point to headless service with traefik 2.3? Thanks in advance for your help.

Resolved !

The error came from a misconfiguration of my service and endpoints.

The name I set for the port of my endpoints didn't match the name of the port of the service (in fact, I didn't set a name). Once the ports in the endpoints and the ports in the services have the same name set, everything worked fine.

kind: Endpoints
apiVersion: v1
metadata:
  name: central-db-service
  namespace: dev
subsets:
  - addresses:
        - ip: 192.168.0.50
    ports:
      - port: 5984
        name: central-db-service
---
kind: Service
apiVersion: v1
metadata:
  name: central-db-service
  namespace: dev
spec:
  clusterIP: None
  ports:
  - port: 5984
    targetPort: 5984
    name: central-db-service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM