Skip to main content
Bob has just been handed a Kubernetes cluster and his first task is to evaluate how secure the cluster’s networking is. This small cluster has two nodes and everything runs in the default namespace. The relevant workloads are:
  • A Deployment called Deploy A running one pod.
  • A standalone Pod called Pod B.
  • A MySQL database running in a pod named MySQL that holds the team’s data.
Each workload is reachable inside the cluster via a Service. A Service provides a stable DNS name and port so other pods can reach an application even if the backing pod is re-created. In this cluster:
  • Deploy A is exposed by Service A.
  • Pod B is exposed by Service B.
  • The database is exposed by a Service named mysql on port 3306.
Which of these pods should be talking to the database? Deploy A is the application that must read and write the team’s data — it needs database access. Pod B is unrelated and should never query MySQL. Bob’s key question: can Pod B reach the database despite not needing to? By default, Kubernetes uses a permissive networking model: every pod in the cluster can open network connections to every other pod — across pods, namespaces, and nodes. That makes development simple, but it increases risk.
A diagram of four smiling pod icons labeled "deploy-a", "pod-b", "mysql", and "coredns" placed on two hosts ("controlplane" and "node01") with arrows showing network connectivity between every pod. The title reads "Every Pod Reaches Every Pod," illustrating full pod-to-pod communication.
Consider this threat: if Pod B runs a small utility with a vulnerability and an attacker compromises it, that attacker is already inside the cluster network. By default, they can open a TCP connection to port 3306 on the database service without needing to compromise Deploy A first. One compromised pod can expose the entire dataset. What Bob needs is a way to say: “only Deploy A may talk to MySQL; everyone else is denied.” Kubernetes provides a declarative object for that purpose: a NetworkPolicy. A NetworkPolicy is a Kubernetes resource that defines allowed ingress and egress traffic for selected pods. You express rules in YAML and apply them to the cluster; the cluster’s network plugin (CNI) enforces the rules.
NetworkPolicy objects only have effect if your CNI/network plugin implements them. Popular CNIs that support NetworkPolicies include Calico, Cilium, and kube-router. If your CNI does not enforce policies, creating NetworkPolicy resources will not restrict traffic.
Before changing anything, Bob wants proof the cluster is as open as it appears. He performs an inventory and then runs connectivity checks from inside pods so tests reflect real application traffic. Cluster inventory
  • Questions to answer:
    • How many Deployments exist in the default namespace?
    • How is Deploy A exposed (which Service)?
    • Which port does Service B expose?
Quick commands to inspect the cluster (run from your workstation):
Summary of the example cluster resources: Connectivity tests
  • From inside the appropriate pods, Bob checks:
    • Can Deploy A reach the mysql Service on port 3306? (It should.)
    • Can Pod B reach the mysql Service on port 3306? (This is the concerning case.)
We use Netcat (nc) to test TCP connectivity. Netcat attempts to open a TCP connection to a host and port and reports whether anything answered. Execute it from inside the pod so the traffic originates where real application traffic would. Common ways to run the tests:
  1. Start an interactive shell in a pod, then run netcat:
  1. Run netcat directly via kubectl exec (no interactive shell):
Note: Netcat flags vary by implementation. The examples above use common flags: -v for verbose and -z to scan for listening daemons without sending data. If the container image lacks nc, you can run the same test using a simple BusyBox or GNU Inetutils image that includes a compatible utility:
  • BusyBox: busybox nc (or use a BusyBox container image)
  • GNU Inetutils: provides nc on images that include inetutils
Make your guess: will Pod B be able to reach the MySQL service on port 3306? Make your guess before continuing.
A schematic diagram titled "Proof Before Changes" showing Kubernetes pods (deploy-a, pod-b, mysql) and their services inside the default namespace with arrows indicating network traffic to a MySQL database (port 3306). The left shows a user labeled "Bob" and a NetworkPolicy object is displayed at the bottom.

Watch Video