How to enable default-http-backend in Kubernetes in order to make Ingress work?

11,846

Solution 1

I have tested this behavior on my cluster. When I tried configuration provided by you I got below Warning:

@microk8s:~$ microk8s kubectl get ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress

Also if you will describe it you will get the same Warning.

@microk8s:~$ kk describe ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             hello-ing
Namespace:        default
Address:          
    Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /hello   hello-svc:80   10.1.128.202:8080)

There is similar Github question regarding this error.

The output you see is just a default for when there is no default backend https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L2393

However, it's working normally.

$ curl 127.0.0.1/hello
Hello, world!
Version: 1.0.0
Hostname: hello-647c466dbc-99rml

If you would add default backend you would get output like:

Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             ingress
Namespace:        default
Address:          127.0.0.1
Default backend:  test2:80   10.1.128.205:80)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /hello   hello-svc:80   10.1.128.204:8080)

and Ingress looks like:

spec:
  backend:
    serviceName: test2
    servicePort: 80
  rules:
  - http:
      paths:
      - path: /hello
        backend:
          serviceName: hello-svc
          servicePort: 80

Though I cannot understand why something that worked half a year ago doesn't work now.

As new apiVersion changes a bit syntax, adding some features, parameters, etc, there might be situation when after update/upgrade some resources cannot be validated anymore by Kubernetes. As stated in this article.

An object definition in Kubernetes requires an apiVersion field. When Kubernetes has a release that updates what is available for you to use—changes something in its API—a new apiVersion is created. However, the official Kubernetes documentation provides little guidance on apiVersion. This guide gives you a cheat sheet on which version to use, explains each version, and gives you the timeline of releases.

If you would only change apiVersion in your YAML, you would get error:

error: error validating "ingress.yaml": error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend]; if you choose to ignore these errors, turn validation off with --validate=false

To sum up, you got this <error: endpoints "default-http-backend" not found> as there was no default backend configured.

For more details you can check Kubernetes Api Docs.

Solution 2

The default backend is a fallback for when the ingress controller cannot match any of the rules.

apiVersion: networking.k8s.io/v1

spec:
  defaultBackend:
    service:
      name: tea-svc
      port:
        number: 80

Here is a complete example using v1

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
spec:
  defaultBackend:
    service:
      name: tea-svc
      port:
        number: 80
  rules:
    - host: cafe.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: tea-svc
                port:
                  number: 80

apiVersion: networking.k8s.io/v1beta1

Depending on the apiVersion of your yaml file, the default backend is specified in a different format. It looks like you are using the beta format.

spec:
    backend:
        serviceName: tea-svc
        servicePort: 80

The NGINX Ingress Controller complains about v1beta1, so far it works in kubernetes 1.21.2, but as the warning says it won't soon:

networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Share:
11,846
Sasha Shpota
Author by

Sasha Shpota

I love building applications with Java, Go, Kotlin, JS/TS, Docker, and Kubernetes. I believe modern engineers must learn fast, switch technologies when needed and develop their expertise in different areas. Find me on my: ( Blog | Twitter | GitHub )

Updated on June 11, 2022

Comments

  • Sasha Shpota
    Sasha Shpota almost 2 years

    I have a single node Kubernetes instance from microk8s. It is installed on a Ubuntu Server 20.20 running on Raspberry Pi 4.

    I am tring to setup an ingress resource which cannot get working.

    When I run kubectl describe ingress my-ingress I get this output

    Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
    

    From what I found in the internet, default-http-backend is something that should have been there by default, but when I run kubectl get pods -n kube-system I don't see it.

    Question: How to enable default-http-backend in mikrok8s? Or more generally, how do I make ingress work?

    Note: Ingress and DNS addons are enabled.