To fix the error error: unable to recognize "ingress.yaml": no matches for kind "Ingress" in version "extensions/v1beta1 you need to set apiVersion to the networking.k8s.io/v1. From the Kubernetes v1.16 article about deprecated APIs:
- NetworkPolicy in the extensions/v1beta1 API version is no longer served
– Migrate to use the networking.k8s.io/v1 API version, available since v1.8. Existing persisted data can be retrieved/updated via the new version.
Now moving to the second issue. You need to add a few annotations and make few changes in your Ingress definition to make dashboard properly exposed on the microk8s cluster:
- add
nginx.ingress.kubernetes.io/rewrite-target: /$2annotation - add
nginx.ingress.kubernetes.io/configuration-snippet: | rewrite ^(/dashboard)$ $1/ redirect;annotation - change
path: /dashboardtopath: /dashboard(/|$)(.*)
We need them to properly forward the request to the backend pods – good explanation in this article:
Note: The “nginx.ingress.kubernetes.io/rewrite-target” annotation rewrites the URL before forwarding the request to the backend pods. In /dashboard(/|$)(.*) for path, (.*) stores the dynamic URL that’s generated while accessing the Kubernetes Dashboard. The “nginx.ingress.kubernetes.io/rewrite-target” annotation replaces the captured data in the URL before forwarding the request to the kubernetes-dashboard service. The “nginx.ingress.kubernetes.io/configuration-snippet” annotation rewrites the URL to add a trailing slash (“/”) only if ALB-URL/dashboard is accessed.
Also we need another two changes:
- add
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"annotation to tell NGINX Ingress to communicate with Dashboard service using HTTPs - add
kubernetes.io/ingress.class: publicannotation to use NGINX Ingress created by microk8singressplugin
After implementing everything above, the final YAML file looks like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^(/dashboard)$ $1/ redirect;
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
kubernetes.io/ingress.class: public
name: dashboard
namespace: kube-system
spec:
rules:
- http:
paths:
- path: /dashboard(/|$)(.*)
pathType: Prefix
backend:
service:
name: kubernetes-dashboard
port:
number: 443
It should work fine. No need to run microk8s proxy command.