Networking in Kubernetes
Networking is a central part of Kubernetes, but it can be challenging to understand exactly how it is expected to work. There are 4 distinct networking problems to address:
- Highly-coupled container-to-container communications
- Pod-to-Pod communications
- Pod-to-Service communications
- External-to-Service communications
Table of Contents
Why is Networking Important in Kubernetes?
Networking in Kubernetes provides the communication path between different components. It ensures that these components can communicate with each other and with other applications or systems.
Creating Network Policies
You can create Network Policies using the kubectl apply -f
with a Network Policy YAML, or via the Kubernetes API.
Using Network Policies
Network Policies specify how groups of pods are allowed to communicate with each other and other network endpoints.
Networking Limitations
Network Policies are implemented by the network plugin, so you must be using a networking solution which supports NetworkPolicy.
Cheat Sheets
Name | Command |
---|---|
Create a Network Policy | kubectl apply -f networkpolicy.yaml |
Get Network Policies | kubectl get networkpolicies |
Describe a Network Policy | kubectl describe networkpolicy <NAME> |
Delete a Network Policy | kubectl delete networkpolicy <NAME> |
Get a Network Policy’s podSelector field | kubectl get networkpolicy <NAME> -o jsonpath='{.spec.podSelector}' |
Get a Network Policy’s specific podSelector field | kubectl get networkpolicy <NAME> -o jsonpath='{.spec.podSelector.<KEY>}' |
Patch a Network Policy | kubectl patch networkpolicy <NAME> -p '{"spec":{"podSelector":{"key":"new value"}}}' |
Replace a Network Policy | kubectl replace -f networkpolicy.yaml |