Interview Prep/Networking/Kubernetes, Containers, MTU & Performance Basics

What is a Kubernetes NetworkPolicy?

IntermediateConceptKubernetes, Containers, MTU & Performance Basics
Answer

A namespaced resource that restricts pod ingress and egress by pod selector, namespace selector, IP block and port. By default all traffic is allowed; once a pod is selected by any policy, only the allowed flows are permitted. It is enforced by the CNI, so Flannel alone ignores it.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: db-allow-app, namespace: shop}
spec:
  podSelector: {matchLabels: {app: db}}
  policyTypes: [Ingress]
  ingress:
  - from: [{podSelector: {matchLabels: {app: api}}}]
    ports: [{protocol: TCP, port: 5432}]
All Networking questions Roadmap: Networking for DevOps

More on Kubernetes, Containers, MTU & Performance Basics