Kubectl Show Ports
You run a kubectl show ports check by reading pod and service objects in your cluster. The command queries the Kubernetes API server and returns the exposed network ports for each target. Teams often run these checks to fix broken network paths between apps. To move fast, admins sometimes give engineers broad cluster roles. Broad roles let users read far more than just port numbers. A user with wide read rules might also view sensitive configs or run commands inside pods. How a kubectl show p
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 run a kubectl show ports check by reading pod and service objects in your cluster. The command queries the Kubernetes API server and returns the exposed network ports for each target.
Teams often run these checks to fix broken network paths between apps. To move fast, admins sometimes give engineers broad cluster roles. Broad roles let users read far more than just port numbers. A user with wide read rules might also view sensitive configs or run commands inside pods.
How a kubectl show ports workflow operates
Kubernetes does not have a single built-in verb just for port numbers. Instead, ports live inside the spec fields of pod and service resources. When an engineer runs a kubectl show ports lookup, the client asks the API server for those objects. The client then reads the container port list or the service port map from the response.
The API server checks Role-Based Access Control rules before it sends any data back. In Kubernetes RBAC, a Role sets rules within a single namespace. A ClusterRole sets rules across the whole cluster and can cover all namespaces. A RoleBinding links a user or group to a Role in one namespace. A ClusterRoleBinding grants those permissions across the entire cluster.
RBAC permissions in Kubernetes are purely additive. There are no deny rules in this system. If you want an engineer to check ports, you grant read permissions on pods and services. The API server checks if a binding gives the user the right verb on those resources. If the rule matches, the API server returns the full pod or service object.
What native RBAC solves and what it leaves open
Native Kubernetes RBAC is great for controlling who can read cluster objects. You can scope a Role to one namespace so a team only sees its own apps. You can also separate read rules on main resources from subresources. In RBAC, subresources use a slash in the resource name, such as the pod logs subresource. This lets admins allow pod inspection without granting rights to exec into containers.
Still, native RBAC only decides who logs in and which API objects they can fetch. It does not inspect what individual commands or requests do in flight. When a user fetches a pod spec to check a port, they get the entire pod spec. That spec might hold plain-text env vars or other details they do not need.
Show Ports: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The gap grows wider when engineers need to test an open port or debug a live app. Admins often grant subresource rules for port forwarding or container exec sessions. Once the API server allows that session, native RBAC steps out of the way. It cannot filter individual shell commands or rewrite sensitive fields like emails or card numbers in output. Teams need fine-grained controls that act on each command and response in real time.
Scoping read roles for safe port checks
To keep native permissions tight, start with a dedicated Role in each namespace. Grant only the read verbs needed to view services and pods. Avoid using a ClusterRoleBinding when an engineer only works in one or two namespaces. Because RBAC has no deny rules, you cannot subtract permissions from a broad binding later.
Keep subresource permissions out of your standard read roles. An engineer who just needs to check port mappings does not need container exec rights. Separate your day-to-day read roles from break-glass roles used for live container debugging. Review your bindings often to make sure old roles do not pile up on user accounts.
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 HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.
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. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.
Frequently asked questions
Why is there no single command just to list ports in Kubernetes?
Kubernetes stores port details inside pod, deployment, and service objects rather than as separate API resources. Your client fetches the parent object from the API server and extracts the port fields for display.
Which RBAC permissions let a user view pod and service ports?
A user needs a Role or ClusterRole that grants read verbs on pod and service resources. An admin must bind that role to the user with a RoleBinding or a ClusterRoleBinding.
Can I block a user from reading ports in one namespace if they have a ClusterRoleBinding?
No, because Kubernetes RBAC rules are purely additive and have no deny rules. To restrict that user, you must remove the ClusterRoleBinding and use separate RoleBindings in each allowed namespace.
Related guides
In this post