Course contentsShow
← Cloud and Infrastructure
Lesson 1237 of 2,98924. Kubernetes NetworkingFree lesson

Ingress Rules Basics

Define ingress rules to control which sources can send traffic to selected pods.

Ingress Rules Basics

What you'll learn: How to define ingress rules that specify which sources are allowed to send traffic to your selected pods.

What Are Ingress Rules?

When you create a NetworkPolicy, you need to explicitly define which incoming traffic is permitted to reach your pods. Ingress rules are the statements within a NetworkPolicy that control who can connect and through which protocol and port. Think of them as a whitelist at the door of a private event—only sources explicitly on the list can enter.

By default, if a pod is selected by any NetworkPolicy, all ingress traffic is denied unless an ingress rule explicitly allows it. This "default deny" behavior is crucial for security: you're building walls first, then carefully opening specific doors.

How Ingress Rules Work

An ingress rule typically specifies:

  • From sources: Which pods, namespaces, or IP addresses can send traffic
  • Ports: Which protocol (TCP/UDP) and port numbers are allowed

The from section defines your allowed sources using selectors—similar to how you selected pods earlier. You might allow traffic from pods with certain labels, entire namespaces, or specific IP ranges outside the cluster.

For example, you might create an ingress rule saying "allow TCP traffic on port 8080 from any pod labeled app: frontend." Only those specific pods can reach your selected pods on that port. Everything else is blocked.

Why This Matters

Without ingress rules, your NetworkPolicy would block everything. These rules give you fine-grained control: allowing your frontend to talk to your backend while blocking everything else, or permitting monitoring tools to scrape metrics while denying general access.

Key Takeaway:
Ingress rules in NetworkPolicies define exactly which sources can send traffic to your pods and on which ports, creating a secure, explicit whitelist of allowed connections.