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

Sasha Shpota picture Sasha Shpota · Sep 22, 2020 · Viewed 7.3k times · Source

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.

Answer

PjoterS picture PjoterS · Sep 24, 2020

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.