Kubernetes Concepts
Some special features in Kubernetes environment:
- pods are often killed and respawned
- pods' IP are not fixed
- a group of pods will be load balanced, using a round robin mode. (In such DNS mode, a single hostname can be resolved into multiple IPs)
- kubernetes requires idempotence
- use random uid/gid by default
- In implementing probes, IO blocking may kill probes.
- Resource exhaustion will be more severe
StatefulSet Hostname
The hostnames take the form of <statefulset name>-<ordinal index>
.
Service
A service object acts like an object in k8s networking. It helps find a pod and load balancing.
Finding a Pod
There are two ways of accessing a pod through the corresponding service:
- through service IP
- through service name and resolving it with kube-dns
Load Balancing
One service can do proxy for multiple pods. Therefore, a single DNS hostname can be resolved to multiple IPs.
Service type ClusterIP
uses kube-proxy
's iptables rules to distribute the requests roughly evenly in a round robin manner.
The documentation says:
By default, the choice of backend is round robin.
Although, the round robin distribution of requests may be affected by things like:
- Busy backends
- Sticky Sessions
- Connection-based (if a backend pod has established a TCP session or a secure tunnel with the user hitting the ClusterIP multiple times)
- Custom host-level / node-level iptables rules outside kubernetes
A service is kube-proxy plus iptables.
Research Papers
(HotCloud'16) Design patterns for container-based distributed systems