1

I am currently running a small K3S cluster in order to get familiar with K8S.

I am able to set up pods with ordinary LoadBalancers and get it to work without any problem. However, when I try to get it to work with Ingresses (HAProxy in my case) - I only end up with "default backend -404".

This is the deployment of the pods, based on the default NGINX container:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: notesncrap
  labels:
    app: notesncrap
spec:
  replicas: 2
  selector:
    matchLabels:
      app: notesncrap
  template:
    metadata:
      labels:
        app: notesncrap
    spec:
      containers:
      - name: notesncrap
        image: jselea/notesncrap 
        ports:
        - containerPort: 80

I have also created a Service:

apiVersion: v1
kind: Service
metadata:
  name: notesncrap
  labels:
    app: notesncrap
spec:
  ports:
    - port: 80
  selector:
    app: notesncrap
    tier: frontend

And now the Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: notesncrap
spec:
  rules:
  - host: k8scrap.selea.se
    http:
      paths:
      - path: /
        backend:
          serviceName: notesncrap
          servicePort: 80

I have the understanding that the name and label should be consistent over the .yaml files, and I personally can't see anything really wrong with what I have written.

Thankful for any pointers

EDIT:

As pointed out by the comments - the Ingress is behind a Apache Reverseproxy:

ProxyPass "/" "http://x.x.x.x:80"
ProxyPassReverse "/" "http://x.x.x.x:80"
ProxyRequests On
ProxyPreserveHost On

When I try curl directly against the ingress:

╭─root@sshgateway ~
╰─➤  curl -H "Host:k8scrap.selea.se" http://x.x.x.x                                                                                                                                   
default backend - 404#
3
  • 1
    are you sure that Host is k8scrap.selea.se ? I think that HTTP headers would be helpful in this case
    – confiq
    Commented Jan 4, 2022 at 12:30
  • 1
    @confiq you are correct; I already checked. Seems like default Apache Ubuntu server is being hit instead of the "app" - < server: Apache/2.4.52 (Ubuntu).
    – Kyslik
    Commented Jan 4, 2022 at 14:54
  • @Kyslik Apache is used as a reverseproxy in front of it. I have also tested with "curl -H "Host:k8scrap.selea.se" " against the ingress directly
    – Orphans
    Commented Jan 5, 2022 at 7:05

1 Answer 1

0

Apparently - I forgot annotations and ingressclass:

I first added this:

apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  annotations:
    ingressclass.kubernetes.io/is-default-class: "true"
  generation: 1
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: haproxy
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: haproxy-ingress-controller
  name: haproxy
spec:
  controller: haproxy.org/ingress-controller

And in the ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: notesncrap
  annotations:
    kubernetes.io/ingress.class: "haproxy"
  generation: 1
spec:
  rules:
  - host: k8scrap.selea.se
    http:
      paths:
      - path: /
        backend:
          serviceName: notesncrap
          servicePort: 80

Please observe the annotation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.