how treafik expose cross namespace service in kubernetes

2/2/2020

My treafik(v2.0) service is in kube-system namespce,now I want to expose namespace dabai-fat eureka service. This is my expose route config of treafik:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: fat-eureka-route
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`k8s-fat-eureka.example.com`) 
      kind: Rule
      services:
        - name: eureka
          port: 8761

the problem is eureka service in namespace dabai-fat.when I check the ingress log:

kubectl logs --follow --since=10s traefik-ingress-controller-hx4xd --namespace kube-system

the output is:

{"ingress":"fat-eureka-route","level":"error","msg":"Cannot create service: service not found kube-system/eureka","namespace":"kube-system","providerName":"kubernetescrd","serviceName":"eureka","servicePort":8761,"time":"2020-02-02T14:35:18Z"}

how to specify the dabai-fat namespace.

-- Dolphin
kubernetes

1 Answer

2/2/2020

The IngressRoute and service should be in the same namespace.You need to create IngressRoute in dabai-fat namespace where you have eureka service and pods.

So your IngressRoute should look like below:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: fat-eureka-route
  namespace: dabai-fat
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`k8s-fat-eureka.example.com`) 
      kind: Rule
      services:
        - name: eureka
          port: 8761
-- Arghya Sadhu
Source: StackOverflow