When using nginx-ingress you can use default backend annotation. In documentation you can read:
This annotation is of the form
nginx.ingress.kubernetes.io/default-backend: < svc name > to specify a
custom default backend. This < svc name > is a reference to a service
inside of the same namespace in which you are applying this
annotation. This annotation overrides the global default backend.
This service will be handle the response when the service in the
Ingress rule does not have active endpoints. It will also handle the
error responses if both this annotation and the custom-http-errors
annotation is set.
So you can just create your default service pointing to some backend (pod) serving your static website
So your ingress now should look like this:
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/default-backend: default-backend
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: myservice
servicePort: 80
and your default service like this:
---
apiVersion: v1
kind: Service
metadata:
name: default-backend
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 80
For accessing external static resources I tried using service of type ExternalService
but it seems to crash my nginx-ingress-controller
pod so I wouldn't recommend using it. If you want to access external resources (outside of cluster) create pod that will proxy requests to this external service and point your ingress's default-backend to its service.
Let me know if this helped