Cilium Network Policy Overview
The Cilium network policy is defined with key components to enforce encryption for your application’s traffic. Here’s a breakdown of the essential elements:- API Version: The configuration uses
"cilium.io/v2", specifying that this is a Cilium-specific network policy. - Kind: The policy type is set as
CiliumNetworkPolicy, indicating that Cilium will manage the enforcement. - Metadata: The policy is named
allow-encrypted-traffic. - Endpoint Selector: It targets all pods with the label
app: myapp, ensuring that the policy applies specifically to your application. - Egress Rules: The rules allow outbound traffic directed to pods with the same label (
app: myapp) over TCP port 80. This ensures encrypted traffic flows only to designated pods.
Complete Cilium Network Policy
Below is the full YAML configuration for the Cilium network policy:Verify Encrypted Traffic Between Pods
To ensure that traffic between pods is properly encrypted, you can capture and inspect network packets using thetcpdump utility. Follow these steps:
- Launch a Pod Shell: Open a shell session in one of the pods.
- Install tcpdump: Update the package list and install
tcpdump. - Monitor Network Traffic: Use
tcpdumpto capture packets on theeth0interface.
Ensure you replace
<pod-name> with the actual name of your pod when executing the commands.tcpdump, you can verify that no unencrypted packets are transmitted. When encryption is properly enabled, the captured traffic should appear encrypted and secure.