Kubernetes Networking & Network Policies Interview Questions

Reviewed by Mark Dickie · Last updated

8 questions on this page you can answer and see marked on the spot. Go to the first one

Kubernetes network policies are rules that control which pods can talk to each other and to external endpoints, operating at the IP layer (Layer 3/4) rather than the application layer. For interviews, you should know that pods are non-isolated by default; traffic flows freely until a policy selects them, and once any policy selects a pod, it becomes isolated in the directions that policy covers. You also need to understand how NetworkPolicy objects use label selectors to target pods and namespaces, the difference between ingress and egress rules, and how the CNI plugin in use (Calico, Cilium, Weave) determines whether policies are even enforced.

What does a Kubernetes networking interview test?

ConceptWhat to know
Default pod isolationPods are reachable by default; a NetworkPolicy selecting a pod makes it isolated
Ingress rulesControl incoming connections to selected pods
Egress rulesControl outgoing connections from selected pods (requires plugin support)
Label selectorspodSelector and namespaceSelector match the pods/namespaces a policy applies to
CNI dependencyPolicies only work if the CNI plugin implements them; flannel alone does not

How do network policies differ from firewall rules?

  1. Policies apply at the pod level, not the node or host level, so they follow pods wherever they schedule.
  2. A single NetworkPolicy can combine podSelector, namespaceSelector, and ipBlock in one from or to entry; rules are additive and there is no explicit deny action.
  3. If two policies select the same pod, their allowed traffic is unioned; you cannot write a separate deny rule to subtract from that union.
  4. Egress policies are part of the networking.k8s.io/v1 API (stable since Kubernetes 1.7) but still depend on CNI plugin support, so not every cluster enforces them.

What mistakes do candidates commonly make?

Assuming all CNI plugins support NetworkPolicy is the most common error. A cluster running flannel in its default configuration will happily accept your NetworkPolicy YAML and silently ignore it. The second frequent mistake is confusing pod isolation with namespace isolation: creating a namespace does not restrict traffic on its own; only a policy that selects pods by namespace label does. Remember also that ipBlock entries are evaluated by the CNI plugin, not by the API server, and plugins differ in how they handle overlapping CIDRs or cluster-internal IPs inside an ipBlock.

Key facts

  • Tarmac's Kubernetes interview questions cover 23 questions at difficulty 1–5 of 5.
  • Tarmac tracked 2,661 job postings asking for Kubernetes in September 2026.
  • Roles asking for Kubernetes advertise a median base salary of £80,000, across 807 job postings as of September 2026.
  • Tarmac last reviewed these Kubernetes interview questions on 14 October 2026.

At a glance

Questions23
Difficulty1–5 of 5
FormatsTrue / false, Short answer, Multiple answer, Fill in the blank, Multiple choice

What you'll review

  1. network policies

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

True or False: In a Kubernetes NetworkPolicy, an empty podSelector ({}) selects all pods in the policy's own namespace.#

Options

Show answer

True. In a Kubernetes NetworkPolicy, an empty podSelector ({}) matches every pod in the namespace where the policy is created, not pods across the whole cluster. This is why an empty podSelector with no ingress rules is the common idiom for a namespace-wide default-deny policy.

Why:

An empty podSelector in a NetworkPolicy is treated as a wildcard. It matches every pod in the namespace the policy is created in, and it does not reach into other namespaces. This is the standard idiom for a namespace-wide default-deny policy.

In a Kubernetes cluster, what is the default network behavior for a pod's ingress and egress traffic when no NetworkPolicy selects that pod? Explain briefly why.#

Show answer

When no NetworkPolicy selects a pod, all ingress and egress traffic to and from that pod is allowed by default. NetworkPolicies are opt-in restrictions: a pod only becomes restricted when a policy's podSelector matches it.

Why:

Kubernetes NetworkPolicies are opt-in restrictions. With no policy selecting a pod, its traffic flows freely in both directions, so both ingress and egress are allowed. Only when a policy's podSelector matches a pod does it begin enforcing rules on that pod's traffic.

Which of the following fields can be used as a peer in a Kubernetes NetworkPolicy ingress or egress rule (under from or to) to specify allowed traffic sources or destinations? Select all that apply.#

Options

Pick every one that applies.

Show answer

The peer selectors allowed in a Kubernetes NetworkPolicy ingress or egress rule are podSelector, namespaceSelector, and ipBlock. They match pods by label, namespaces by label, and IP addresses by CIDR range. nodeSelector is a Pod scheduling field and is not valid as a NetworkPolicy peer.

Why:

The NetworkPolicyPeer type in the Kubernetes API supports podSelector (match pods by label), namespaceSelector (match namespaces by label), and ipBlock (match by CIDR range). nodeSelector is a scheduling field that appears in Pod specs to choose nodes; it is not a field of NetworkPolicyPeer and cannot be used to filter traffic.

A NetworkPolicy is created in the frontend namespace. Its podSelector is empty ({}), its policyTypes field is ['Ingress'], and its ingress field is an empty list ([]). What is the effect on pods in the frontend namespace?#

Show answer

All ingress traffic to every pod in the frontend namespace is denied because the empty podSelector matches all pods in that namespace and the policy selects Ingress with no allow rules. Egress traffic is unaffected by this policy because Egress is not listed in policyTypes.

Why:

The empty podSelector selects every pod in the frontend namespace. Because policyTypes lists only Ingress, the policy governs incoming traffic for those pods, and because the ingress list is empty there are no allow rules, so all incoming traffic is denied. Egress is not listed in policyTypes, so this policy places no restriction on outbound traffic from those pods.

In Kubernetes, if no NetworkPolicy object selects a pod, that pod accepts all ingress and egress traffic by default. True or false?#

Options

Show answer

A pod that no NetworkPolicy selects is non-isolated, so it accepts all ingress and egress traffic by default. The statement is true. Isolation only begins once a NetworkPolicy selects the pod for a given direction.

Why:

The statement is true. Kubernetes pods are non-isolated by default, meaning they allow all ingress and egress traffic. A pod only becomes isolated in a given direction once a NetworkPolicy selects it and lists that direction in its policyTypes. If no NetworkPolicy selects the pod, nothing isolates it, so all traffic is permitted.

True or false: Kubernetes NetworkPolicies are enforced directly by the kube-apiserver itself, not by the cluster's CNI network plugin.#

Options

Show answer

Kubernetes NetworkPolicies are not enforced by the kube-apiserver, so the statement is false. The API server only stores NetworkPolicy objects. The CNI plugin or network provider, such as Calico, Cilium, or Weave Net, running on each node performs the actual packet filtering.

Why:

This statement is false. The kube-apiserver only stores NetworkPolicy resources and does not implement them. Enforcement, meaning actually allowing or dropping packets, is done by the CNI plugin or network provider (such as Calico, Cilium, or Weave Net) running on each node. If the cluster's CNI does not support NetworkPolicies, the objects have no effect.

By default, before any NetworkPolicy selects a set of pods, how does Kubernetes treat network traffic to and from those pods?#

Show answer

By default, Kubernetes allows all ingress and egress. Pods are non-isolated until a NetworkPolicy explicitly selects them.

Why:

A NetworkPolicy only takes effect for pods it selects via podSelector. Until a policy selects a pod, that pod is non-isolated and no restrictions apply, so all ingress and egress traffic is allowed. Isolation for a pod's ingress or egress direction begins only when a policy selects the pod and declares that direction in its policyTypes.

A NetworkPolicy with podSelector: {} selects which pods?#

Show answer

It selects all pods in the same namespace as the NetworkPolicy. An empty label selector matches every object in its scope, and for spec.podSelector that scope is the policy's own namespace.

Why:

An empty selector matches all objects in its scope. For spec.podSelector, the scope is the NetworkPolicy's own namespace, so the policy applies to every pod in that namespace. Pods in other namespaces are not selected unless a policy in their own namespace selects them.

By default, Kubernetes pods are non-isolated and accept all ingress traffic. When a NetworkPolicy whose policyTypes includes Ingress selects a pod, what happens to ingress traffic that does not match any ingress rule in any applicable NetworkPolicy?#

Show answer

Once a pod is selected by a NetworkPolicy whose policyTypes includes Ingress, that pod becomes isolated for ingress traffic. NetworkPolicy rules act as allow-lists: only ingress traffic that matches at least one ingress rule across all applicable policies is permitted. Any ingress traffic that does not match any rule in any applicable NetworkPolicy is implicitly denied, meaning the packets are dropped. This is default-deny behavior for isolated pods, not a deny-list model.

Why:

Kubernetes uses a default-deny model for isolated pods. Once a NetworkPolicy with Ingress in its policyTypes selects a pod, the pod becomes isolated for ingress. Only traffic matching at least one ingress rule across all applicable policies is permitted; everything else is implicitly denied. NetworkPolicy rules function as allow-lists, not deny-lists, so unmatched traffic is dropped automatically.

In a Kubernetes NetworkPolicy, what does an empty namespaceSelector ({}) match, and what does an empty podSelector ({}) match?#

Show answer

An empty namespaceSelector ({}) inside a from or to peer matches every namespace in the cluster, so it selects pods in all namespaces. An empty podSelector ({}) matches every pod in the namespace where the NetworkPolicy is defined. Combining both in one peer (an empty podSelector and an empty namespaceSelector) allows traffic from all pods in all namespaces. A default-deny policy for a namespace is different: it uses an empty podSelector at the spec level with policyTypes set and no ingress rules.

Why:

In Kubernetes NetworkPolicies, an empty label selector {} acts as a match-everything wildcard. An empty namespaceSelector within a peer selects all namespaces in the cluster, while an empty podSelector (at the policy spec level or within a peer) selects all pods within the NetworkPolicy's own namespace. Within a single peer, the podSelector and namespaceSelector are ANDed, so both being empty allows all pods in all namespaces. A namespace-wide default-deny is instead built from an empty spec-level podSelector with no ingress rules.

In a Kubernetes namespace that has no existing NetworkPolicy objects, you create a NetworkPolicy whose podSelector matches a specific Deployment's pods. The policy sets policyTypes: [Ingress] and has one ingress rule that allows traffic from a particular namespace. Assume the cluster's CNI enforces NetworkPolicy. What is the effect on traffic to and from the selected pods?#

Show answer

Inbound traffic to the selected pods is restricted: only traffic matching the ingress rule (from the specified namespace) is allowed, and other ingress is denied. Outbound traffic from those pods is not restricted, because Egress is not listed in policyTypes and no egress rules are defined, so egress remains unrestricted.

Why:

A NetworkPolicy only isolates the traffic direction(s) listed in policyTypes for the pods its podSelector matches. Here policyTypes is [Ingress], so inbound traffic to the selected pods is denied except what the ingress rule allows from the named namespace. Egress is absent from policyTypes and no egress rules exist, so the selected pods' outbound traffic is not restricted by this policy. Pods outside the selector are not affected.

In a Kubernetes NetworkPolicy, the _____ field selects which Pods the policy applies to within the namespace. When this field is set to an empty map {}, the policy applies to _____ Pods in that namespace.#

Show answer

In a Kubernetes NetworkPolicy, the **podSelector** field selects which Pods the policy applies to within the namespace. When this field is set to an empty map {}, the policy applies to all Pods in that namespace.

Why:

The podSelector field in a NetworkPolicy's spec determines which pods in the namespace the policy governs. An empty podSelector ({}) has no label requirements, so it matches every pod in the namespace, and the policy effectively applies to all pods in that namespace.

In Kubernetes, a NetworkPolicy sets policyTypes: [Ingress] and selects certain pods through its podSelector, but defines no ingress rules (the ingress field is absent or empty). What is the effect on inbound network traffic to those selected pods?#

Show answer

All ingress traffic to the selected pods is denied. When policyTypes includes Ingress but no ingress allow-rules are defined, the allow-list is empty, so no inbound traffic is permitted. This is the default-deny behavior for ingress.

Why:

When a NetworkPolicy lists Ingress in its policyTypes, the pods it selects become isolated for ingress, so only traffic matched by an ingress rule is allowed. If no ingress rules are provided, the set of permitted ingress sources is empty, so every inbound connection to the selected pods is blocked. This is the default-deny semantics for ingress; only traffic explicitly matched by at least one ingress rule would be permitted.

In a Kubernetes NetworkPolicy ingress rule, a single from entry that sets both namespaceSelector and podSelector allows traffic only from pods matching the podSelector that run in namespaces matching the namespaceSelector. True or false?#

Options

Show answer

A single from entry in a NetworkPolicy ingress rule that sets both namespaceSelector and podSelector is valid and restricts traffic to pods matching the pod labels inside the matching namespaces. The two selectors in one entry are ANDed, so pods with other labels, or pods in other namespaces, are blocked by that entry.

Why:

Within a single from entry, a namespaceSelector and a podSelector are combined with a logical AND. The namespaceSelector first picks the namespaces, and the podSelector then restricts the allowed sources to pods with matching labels inside those namespaces. This is what enables precise cross-namespace control, such as allowing only pods labeled app=frontend in the staging namespace. The statement is therefore true. (Separate from entries, by contrast, are combined with OR, which is a different behavior.)

In Kubernetes (networking.k8s.io/v1 NetworkPolicy), you want a default-deny-all-ingress policy for an entire namespace. You set policyTypes to include Ingress. What value must spec.podSelector be set to so that it matches every pod in the namespace, and which part of the spec must be absent or empty so that all incoming traffic is denied?#

Show answer

Set spec.podSelector to {} (an empty label selector), which matches all pods in the namespace. Leave out the ingress rules, so the ingress field is absent or an empty list. With Ingress in policyTypes and no ingress allow rules, the allow-list is empty and all incoming traffic to the selected pods is denied.

Why:

An empty podSelector ({}) selects every pod in the policy's namespace. Listing Ingress in policyTypes makes the policy govern ingress traffic for those pods. When no ingress rules are defined (the field is absent or an empty list), there are no allow rules, so the default for selected pods is to deny all incoming connections. This is the standard default-deny-all-ingress pattern used to isolate a namespace.

The Kubernetes namespace app-prod contains many pods and currently has no NetworkPolicies. A team applies the following manifest into app-prod:#

Show answer

Only pods in app-prod labeled app=db are selected by the policy. For those pods, ingress is restricted: only TCP connections to port 5432 from pods labeled app=web in the same namespace are allowed, and all other ingress is denied. Egress from app=db pods is not restricted because policyTypes lists only Ingress, so it remains allowed. Pods not labeled app=db are not selected and keep their default allow-all behavior in both directions.

Why:

A NetworkPolicy only affects pods matched by its spec.podSelector, here pods labeled app=db in app-prod. Because policyTypes lists only Ingress, those pods become isolated for ingress only; egress is not governed by this policy and stays allowed. The single ingress rule permits traffic from pods labeled app=web in the same namespace (the from entry has only a podSelector, so it implicitly matches the policy's own namespace) on TCP port 5432. Any other ingress to app=db pods is denied. Pods without the app=db label are not selected, so their connectivity is unchanged. The CNI plugin is what enforces these rules; the API server only stores the manifest.

In the prod namespace, a Kubernetes NetworkPolicy selects pods labeled app=api and includes an ingress rule allowing traffic only from pods labeled app=frontend. No other NetworkPolicy exists in the namespace. What is the effect on ingress traffic to a pod labeled app=api coming from a pod labeled app=worker?#

Show answer

The traffic is denied. Once a pod is selected by any NetworkPolicy, it becomes isolated for the specified policy types. Only traffic explicitly allowed by a matching NetworkPolicy is permitted; all other ingress to that pod is denied. No separate default-deny-all policy is required.

Why:

Once a pod is selected by any NetworkPolicy's podSelector, it becomes isolated for the policy types listed in policyTypes (Ingress here, since the policy has ingress rules). Only traffic explicitly allowed by a matching policy is permitted, and all other ingress in that direction is denied. The policy allows only app=frontend, so ingress from app=worker to app=api is denied. No separate default-deny policy is needed, because selection by any NetworkPolicy already triggers isolation.

In a Kubernetes NetworkPolicy, the policyTypes field controls which traffic directions are enforced by isolation. The field accepts two valid values: _____ (for incoming traffic) and _____ (for outgoing traffic). If the field is omitted, it is inferred from the presence of ingress and egress rules in the policy. Fill in both values exactly as the API spells them (case-sensitive).#

Show answer

In a Kubernetes NetworkPolicy, the policyTypes field controls which traffic directions are enforced by isolation. The field accepts two valid values: Ingress (for incoming traffic) and Egress (for outgoing traffic). If the field is omitted, it is inferred from the presence of ingress and egress rules in the policy. Fill in both values exactly as the API spells them (case-sensitive).

Why:

The policyTypes field in a Kubernetes NetworkPolicy accepts exactly two values: Ingress and Egress, spelled with a capital first letter. Ingress enables isolation for incoming traffic, and Egress enables isolation for outgoing traffic. The values are case-sensitive, so lowercase forms such as ingress are not valid policyTypes entries. When the field is omitted, Kubernetes infers the policy types from the rules present: if an ingress section exists, Ingress is implied, and if an egress section exists, Egress is implied.

A Kubernetes cluster has the following NetworkPolicy deployed in namespace app. The app namespace itself has no labels other than kubernetes.io/metadata.name: app.#

Options

Show answer

Only the pod worker1 in the prod namespace can open ingress connections to pods in app. The first from entry requires both a prod namespace label and role=worker, which worker1 alone satisfies. The second entry only matches role=helper pods inside app itself, so no other listed pod qualifies.

Why:

The policy's podSelector: {} selects every pod in app, so it governs ingress to all of them. The two from entries are OR'd, so a source pod needs to match only one. Within the first entry, the namespaceSelector (env=prod) and the podSelector (role=worker) are AND'd, so the source must live in a prod-labeled namespace and carry role=worker; only the worker1 pod meets both conditions. The monitor pod is in prod but has role=helper, so it fails the first entry. The second entry has no namespaceSelector, so its podSelector (role=helper) matches only pods in the policy's own namespace app; no pod there has role=helper, so that entry matches nothing. worker2 is in staging (env=staging, not prod), helper is in dev (no env=prod label and the second entry is same-namespace only), and web is in app with role=worker, which matches neither entry.

A namespace payments contains a single NetworkPolicy with podSelector: {}, policyTypes: [Ingress, Egress], and no ingress or egress entries, which makes it a default-deny for the namespace. After applying it, pods in payments can no longer resolve DNS names (nslookup from inside a pod times out). The cluster runs CoreDNS in the kube-system namespace, and the CoreDNS pods carry the label k8s-app: kube-dns. Assume Kubernetes 1.21+, so namespaces carry the label kubernetes.io/metadata.name.#

Show answer

DNS breaks because policyTypes includes Egress and there are no egress rules, so all outbound traffic from the payments pods is denied, including DNS queries to CoreDNS on port 53. The fix is an additional egress rule (in the same policy or a companion policy) with a to entry that combines a namespaceSelector matching kubernetes.io/metadata.name: kube-system with a podSelector matching k8s-app: kube-dns, plus ports entries for port 53 over both UDP (normal lookups) and TCP (large responses). Because the rule is limited to those pods and that port, every other egress remains denied, and an empty allow-all egress rule is not needed.

Why:

The policy selects every pod in payments and lists Egress in policyTypes without any egress entries, so no outbound connection is allowed. DNS lookups are outbound UDP (and TCP for large responses) to port 53 on the CoreDNS pods, so they are blocked along with everything else. The fix is a narrowly scoped egress rule: a to entry with a namespaceSelector on kubernetes.io/metadata.name: kube-system and a podSelector on k8s-app: kube-dns, with ports for 53/UDP and 53/TCP. Egress policies are evaluated against the destination pod after service translation, so the pod selector is the correct target. Other egress stays denied, and an egress: [{}] rule that allows everything would be too broad.

Namespace app-prod contains pods labeled app=web, app=api, and app=db. Two NetworkPolicies are applied in that namespace, written here as YAML-equivalent specs:#

Options

Pick every one that applies.

Show answer

Web-to-api traffic on any port and api-to-db traffic on TCP 5432 are the only allowed connections here. Web pods are selected by no policy, and the api pods' ingress rule admits web on any port. The api-to-db path is allowed because api egress and db ingress both permit TCP 5432. Reverse db-to-api, web-to-db, and api-to-api connections are rejected by a destination ingress rule or a source egress rule.

Why:

NetworkPolicy is evaluated per pod on both sides: the source pod's egress rules and the destination pod's ingress rules must each allow the flow when that pod is selected by a policy of that type. app=web is selected by no policy, so it is unrestricted in both directions. app=api is selected by Policy 2, which restricts its ingress to app=web (any port) and its egress to app=db on TCP 5432. app=db is selected by Policy 1, which restricts only its ingress to app=api on TCP 5432; its egress is unrestricted because Policy 1 does not declare Egress. Tracing each option: web to api on TCP 8080 has an unrestricted source and an api ingress that admits web on any port, so it is allowed. api to db on TCP 5432 is allowed by api egress to db:5432 and by db ingress from api:5432. db to api on TCP 5432 has an unrestricted source, but api ingress admits only web, so it is denied. web to db on TCP 5432 has an unrestricted source, but db ingress admits only api, so it is denied. api to api on TCP 8080 is denied because api egress permits only db on TCP 5432.

In a Kubernetes NetworkPolicy, an ingress rule's from field contains a single entry that specifies both a namespaceSelector (matching label env=prod) and a podSelector (matching label role=frontend). Explain the precise logical relationship between these two selectors in this configuration, and contrast it with what happens when the same namespaceSelector and podSelector appear as two separate entries in the from array.#

Show answer

Within a single from entry, the namespaceSelector and podSelector are logically ANDed: the podSelector is evaluated only against pods residing in namespaces matched by the namespaceSelector. Ingress is therefore permitted only from pods labeled role=frontend that are in namespaces labeled env=prod. When the same two selectors appear as two separate entries in the from array, they are logically ORed: each entry independently defines a permitted source. The first entry, containing only namespaceSelector matching env=prod, permits ingress from any pod in any namespace labeled env=prod regardless of pod labels. The second entry, containing only podSelector matching role=frontend, matches pods labeled role=frontend only in the NetworkPolicy's own namespace, because a podSelector without a namespaceSelector is scoped to the policy's namespace. The overall effect is ingress from any pod in any env=prod namespace, OR from any role=frontend pod in the policy's own namespace.

Why:

A NetworkPolicy ingress rule's from is a list of NetworkPolicyPeer objects. Selectors placed inside the same list element are combined with AND, so a podSelector alongside a namespaceSelector in one element only matches pods within the namespaces that the namespaceSelector selects. Separate list elements are independent peers combined with OR, so each one adds its own permitted sources. A podSelector used without any namespaceSelector is restricted to the namespace where the NetworkPolicy is defined, which is why the second separate entry matches frontend pods only in the policy's own namespace rather than in every namespace. The YAML for the two forms differs mainly by whether the two selectors share one list bullet, so the bullet placement determines the semantics.

Consider this NetworkPolicy, applied in namespace prod:#

Options

Show answer

Only pods labeled app=api that run in a namespace labeled team=backend may connect on TCP 5432 under this policy. The namespace selector and pod selector inside a single from entry are ANDed, so both must match. Pods in prod qualify only if that namespace also carries team=backend.

Why:

Within a single from entry, a namespaceSelector and a podSelector are ANDed: a source pod is allowed only if its labels match the podSelector and its namespace labels match the namespaceSelector. Adding a namespaceSelector also widens where the podSelector is evaluated, so it applies across every namespace labeled team=backend rather than only prod. The policy has one from entry holding both selectors, so the allowed sources are exactly the app=api pods in team=backend namespaces. The option claiming OR semantics is wrong because OR applies only between separate from entries. The option ignoring the pod selector is wrong because the pod label still must match. The option restricting the pod selector to prod is wrong because a namespaceSelector changes that scope.

Related interview questions

Job market

See kubernetes salaries and hiring demand from live job postings.

Practise these until they stick

That's every question we hold on this topic, and the page marks what you pick. What it can't do is remember. A free account keeps every answer, and what you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 marked answers per 30 days · written feedback on the paid plan

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.