Basic K8s Ingress example

Hi,

I am evaluating Traefik as our pimrary ingress mechanism. I am using the following YAML

kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
  name: myingress
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web

spec:
  rules:
    - host: localhost
      http:
        paths:
          - path: /bar
            backend:
              serviceName: whoami
              servicePort: 80
          - path: /foo
            backend:
              serviceName: whoami
              servicePort: 80
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: whoami
  labels:
    app: containous
    name: whoami

spec:
  replicas: 2
  selector:
    matchLabels:
      app: containous
      task: whoami
  template:
    metadata:
      labels:
        app: containous
        task: whoami
    spec:
      containers:
        - name: containouswhoami
          image: containous/whoami
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: whoami

spec:
  ports:
    - name: http
      port: 80
  selector:
    app: containous
    task: whoami

This doesn't work. I installed Traefik with Helm. Any help would be much appreciated.

Cheers

Can you please describe "what doesn't work"?

Also, logs would be nice :slight_smile:

Hi @mojo,

The HelmChart rely on the CRD provider by default.
From here you have two options to make your example work:

  • Activate the Kubernetes Ingress provider:

When installing the Traefik HelmChart, you must provide a values file as follow:

helm install --namespace traefik traefik traefik/traefik --values values.yaml

And here is the content of the values file:

# values.yaml
additionalArguments:
  - "--providers.kubernetesIngress"
  • Work with IngressRoute CRD:

Replace the Ingress by an IngressRoute resource:

---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: myingressroute
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`localhost`) && Path(`/foo`)
      kind: Rule
      services:
        - name: whoami
          port: 80
    - match: Host(`localhost`) && Path(`/bar`)
      kind: Rule
      services:
        - name: whoami
          port: 80

Thank you this is awesome!

Hi,
If you want traefik can auto discovery Ingress object instead IngressRoute. You have to tell to traefik enable the kubernetes ingress. See below how to do it.

traefik-deploy.yaml

...
            - --api=true
            - --api.insecure=true
            - --api.dashboard=true
            - --accesslog
            - --ping=true
            - --log.level=INFO
            # providers block
            - --providers.kubernetescrd
            - --providers.kubernetesingress=true
...

I'm using both objects IngressRoute and Ingress to route traffic to my services.

Cheers