How to Configure MicroK8s Port Forward
You set up a microk8s port forward by mapping a local port to a pod. This setup sends local network traffic straight through the cluster API server to your app. Engineering teams use this method to test internal services without opening public network routes. Still, granting broad cluster roles for forwarding often gives users too much control over production resources. How a microk8s port forward works under the hood A microk8s port forward relies on the built-in Kubernetes command line tool
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up a microk8s port forward by mapping a local port to a pod. This setup sends local network traffic straight through the cluster API server to your app. Engineering teams use this method to test internal services without opening public network routes. Still, granting broad cluster roles for forwarding often gives users too much control over production resources.
How a microk8s port forward works under the hood
A microk8s port forward relies on the built-in Kubernetes command line tool included with the snap package. When a developer starts a forward session, the local client talks to the cluster API server. The API server checks the user credentials and role rules before it allows the request.
Once the check passes, the API server opens a steady stream to the target node agent. The node agent then links that stream to the specific network space of the target pod. Your local machine listens on a chosen port and wraps all local traffic into this stream.
This workflow means you do not need an external load balancer or a public ingress route. Developers can reach a database pod or a web service pod from their own laptops. The traffic stays inside the encrypted cluster channel from the laptop to the host node.
Setting up role rules for port forwarding
To use this feature, a user needs specific role permissions inside the cluster. The cluster admin must grant permission to view pods and create port forward subresources. If a user tries to forward traffic to a service, the client resolves the backing pod first.
Many teams make the mistake of assigning full admin roles just to let developers debug apps. A broad role lets the user delete pods, read secret keys, or change running workloads. Instead, admins should scope the role to a single namespace and only allow forwarding actions.
You also need to watch how the local port binds on the user machine. By default, the local listener only accepts traffic from the local loopback address on that laptop. If a user binds the listener to all network interfaces, anyone on that local Wi-Fi can reach the pod.
End-to-End Encryption + Forward Proxy Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native cluster roles solve and what they miss
Native cluster role rules are great at deciding who can start a tunnel to a pod. They verify the user identity and check if that user has rights in that namespace. Once that tunnel opens, Still, the cluster API stops inspecting what happens inside the stream.
The native setup treats the forwarded stream as raw bytes moving between the laptop and the pod. If the pod runs a database, the cluster log only shows that a tunnel opened. It does not record which queries the developer ran or which tables they read.
Also, native tunnels do not alter sensitive data flowing back to the developer laptop. If a table holds customer emails, phone numbers, or card numbers, the raw values arrive intact. Data masking that rewrites matched fields in results cannot happen inside a raw port tunnel. Admins also cannot approve or block single database statements once the port is open.
Check Kubernetes API requests and responses on the wire
Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.
Frequently asked questions
Why does my microk8s port forward drop when my pod restarts?
A port forward links directly to a single pod instance, even if you targeted a service name. When that specific pod stops or restarts, the network stream breaks and you must start a new session.
Can I forward a port to a multi-container pod?
Yes, all containers inside the same pod share one network space and one IP address. You just target the port number that the specific app listens on inside that shared pod space.
Does port forwarding work for UDP traffic in MicroK8s?
Standard Kubernetes port forwarding only supports TCP streams through the cluster API server. If your app relies on UDP packets, you will need to use a node port or load balancer instead.
Related guides
In this post