How to perform a port-forward on microk8s and send that process to the background?

I am trying to run this command:

microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443

But the output is the following:

└─[$] <> microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443
Forwarding from 127.0.0.1:10443 -> 8443
Forwarding from [::1]:10443 -> 8443

And this is a "always on" process, is there anyway to perform this configuration without me having to keep a terminal open?


Solution 1:

I'm not familiar with microk8s specifically, but if it behaves like a standard k8s system, then you could create another Service using type NodePort. That would expose the dashboard on a local port on the kubernetes node.

kind: Service
apiVersion: v1
metadata:
  name: k8s-dash
  namespace: kube-system
spec:
  selector:
    app: k8s-dash
  type: NodePort
  ports:
  - name: https
    nodePort: 30443
    port: 443
    targetPort: 443
    protocol: TCP

Change the selector to match what ever the labels the dashboard uses.

Alternatively you could deploy an Ingress Controller (like this one: https://github.com/nginxinc/kubernetes-ingress ) and use an Ingress resource to expose it.

The ingress controller is the more secure route, because you can apply additional protections like ACL, OAUTH2, etc.