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?

2 Answers

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: ) 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.

Though I am not much familiar with Kubernetes, but a general way to keep a command running in background is by using nohup at the beginning and & at the end.

e.g.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like