Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

38%
Kubernetes (K8s) (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Kubernetes Network Policies & Microsegmentation.

senior LevelMost AskedCode ExampleKubernetesSystem Design

In Simple Words: By default, Kubernetes has a flat, open network: any Pod can establish a network socket to any other Pod in the cluster. A NetworkPolicy acts as a stateful firewall for Pods:

yaml
# Production Default: Deny-All Ingress Traffic
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: payment-system
spec:
  podSelector: {} # Applies to ALL pods in namespace
  policyTypes:
    - Ingress

Once default-deny is applied, you write specific ingress rules allowing only authorized traffic (e.g., allow traffic to database Pods on port 5432 only from pods labeled app: order-api).