Kubernetes YAML Networking/Allow ingress from labeled pods

Permit traffic only from a specific app tier.

Section: NetworkPolicy

Allow ingress from labeled pods

yaml
yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-allow-from-web
spec:
  podSelector:
    matchLabels:
      app: api
  policyTypes: ["Ingress"]
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: web
      ports:
        - protocol: TCP
          port: 8080

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing NetworkPolicy
Default deny ingress policy
Block incoming traffic until explicitly allowed.
OpenIn sheetyamlsame section
ClusterIP Service YAML
Expose Pods internally in the cluster.
Basic Ingress YAML
Route traffic by host and path.
NodePort Service YAML
Expose the service on each node's IP.
Enable TLS on Ingress
Terminate HTTPS with a Secret-backed certificate.
LoadBalancer Service YAML
Request external load balancing from the platform.