Kubernetes’ built-in networking capabilities include service discovery, load balancing, and network policies. These capabilities are provided through various components and APIs in the Kubernetes system.
Service discovery is the ability of a service to locate and communicate with other services in the network. Kubernetes achieves service discovery through the use of labels and selectors. Labels are key-value pairs attached to Kubernetes objects, such as pods, services, and nodes. Selectors are used to query objects based on their labels. For example, a service can use a selector to find all pods with a specific label and communicate with them.
Load balancing is the distribution of network traffic across multiple resources to improve responsiveness and availability. Kubernetes provides built-in load balancing through the use of services. A service is a logical abstraction over a set of pods, and it provides a stable IP address and DNS name that can be used to access the pods. Kubernetes automatically load balances traffic to the pods by using the kube-proxy component. The kube-proxy can use different load balancing algorithms, such as round robin and least connections, to distribute traffic.
Network policies are a way to control the flow of traffic between pods in a cluster. Network policies use labels and selectors to define rules for traffic filtering and forwarding. A network policy can allow or deny traffic based on the source and destination pods, the namespace, and the port. Network policies are implemented by the network plugin, which is responsible for enforcing the rules on the pods.
Here are some examples of Kubernetes networking capabilities:
- Pod-to-Pod communication: Pods in a cluster can communicate with each other using their IP addresses. The IP addresses are unique within the cluster and are assigned to the pods when they are created. Pods can also communicate with each other using the localhost address if they are in the same pod.
- Pod-to-Service communication: A service is a logical abstraction over a set of pods, and it provides a stable IP address and DNS name that can be used to access the pods. Pods can communicate with a service by using its IP address or DNS name. The kube-proxy component load balances the traffic to the pods.
- Service-to-Service communication: Services can communicate with each other using their IP addresses or DNS names. The kube-proxy component load balances the traffic to the pods.
- External-to-Service communication: External clients can communicate with a service using its IP address or DNS name. The kube-proxy component load balances the traffic to the pods.
Here are some resources for learning more about Kubernetes networking:
- Kubernetes Networking Guide: This guide provides an overview of the Kubernetes networking components and their implementation.
- Declare Network Policy | Kubernetes: This document helps you get started using the Kubernetes NetworkPolicy API to declare network policies that govern how pods communicate with each other.
- Services, Load Balancing, and Networking | Kubernetes: This document provides an overview of the concepts and resources behind networking in Kubernetes.
- A visual guide to Kubernetes networking fundamentals | Opensource.com: This article provides a visual guide to the Kubernetes networking fundamentals.
Sources:
- Inside Kubernetes Networking - Dominik Tornow, Cisco
- k8snetlook – Root-Causing k8s Network Problems in an Automated Way - Arun Sriraman, VMware
- Enhancing K8s Networking with SmartNICs - Dave Cremins, Intel
- Kubernetes Networking Intro and Deep-Dive - Bowei Du & Tim Hockin, Google
- Inside Kubernetes Ingress - Dominik Tornow, Cisco
- Troubleshooting On-Premise Kubernetes Network: Underlay, Overlay and Pod - Tomofumi Hayashi, RedHat
- Back to basics: accessing Kubernetes pods
- The Kubernetes Networking Guide
- Declare Network Policy | Kubernetes
- Guest Post: How Clarifai uses NATS and Kubernetes for their Machine Learning Platform | NATS blog
- A visual guide to Kubernetes networking fundamentals | Opensource.com
- Services, Load Balancing, and Networking | Kubernetes
- API Gateways Overview | Consul | HashiCorp Developer
- Cluster Networking | Kubernetes
- Networking in the Brave New World of Containers – Sweetcode.io
- Pods, services, deployments… what do I use when?
- Exposing Applications for Internal Access | Kube by Example