Skip to content

Instantly share code, notes, and snippets.

@EliFuzz
Created August 28, 2023 07:11
Show Gist options
  • Save EliFuzz/75cb40aa6570fa09173c2998f85af7e1 to your computer and use it in GitHub Desktop.
Save EliFuzz/75cb40aa6570fa09173c2998f85af7e1 to your computer and use it in GitHub Desktop.
Best Practices: Network Policies
Aspect Description
Isolate Namespaces, Pods, and Services Use network policies to block all incoming and outgoing traffic by default, and then create additional policies to allow specific types of traffic
Enforce Security Policies Create network policies that follow organizational security standards or comply with regulatory requirements
Implement Micro-Segmentation and Zero Trust Networking Use network policies to restrict communication between microservices or verify the identities and authorizations of pods before allowing traffic
Group Pods and Services Based on Labels Use labels like "app" (e.g., frontend or backend) or "name" (e.g., dev or prod) to categorize pods and services, and create network policies that match these labels
Specify Traffic Types Using Ports and Protocols Define which types of traffic are allowed or denied using ports (e.g., TCP on port 80 or 443) or protocols (e.g., UDP on port 53)
Block Specific IP Addresses or Ranges Restrict traffic from certain IP ranges or individual addresses using CIDR notation (e.g., 10.0.0.0/8 or 192.168.0.0/16)
Allow Only From Specific Namespaces Apply network policies to specific namespaces using selectors (e.g., default or kube-system), and deny traffic from others (e.g., kube-public or kube-node-lease)
Default Deny-All Policy Establish a default deny-all policy that blocks all traffic, and then add specific allow rules for essential connections
Flexible and Scalable Policies Avoid hard-coding IP addresses or port numbers by grouping pods and namespaces using labels and selectors
Troubleshooting and Debugging Tools Utilize tools like kubectl, Calicoctl, or NetworkPolicyStats to identify issues or optimize policies
Regular Reviews and Updates Periodically review and modify network policies to maintain consistency, effectiveness, and prevent conflicts or errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment