10. K8 Services
Last updated
Last updated
Each pod has its own IP address
Pods are ephemeral - destoryed frequently
Service gives stable IP address
Provides load balancing
default type
pod gets ip address from node's range
How Service Knows which Pod to Forward Request to
How Service Knows which Port to Forward Request to
Service Endpoints
K8 create endpoints object
have same name as service
keeps track of which pods are members/endpoint of the service
Multiple Ports Service
clients want to communicate with 1 specific pod directly
pod wants to talk directly with specific pod not a randomly selected pod
Use Case: Stateful applications like databases
pod replicas are not identical
Client needs to figure out IP address of each pod
Option 1 - API call to K8 API Server (X)
Option 2 - DNS Lookup (Recommended)
DNS lookup for service - returns single ip address
If ClusterIP is set to None - returns pod ip address instead
ClusterIP
Only accessible within cluster
NodePort
extension of clusterip service
External traffic has access to fixed port on each worker node
not secure and efficient since port is directly accessible externally
not used in production environments
Load Balancer
extension of nodeport service
becomes accessible externally through cloud provider loadbalancers
secure and efficient since port is not accessible directly but via load balancer
used in production environments