default, kube-system, kube-public,
kube-node-lease
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3 # tells deployment to run 3 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kube-proxy manage routing to backend Pods.NodeIP:NodePort.selector — a label query used to find matching Pods.selector: app=nginx matches all Pods with label app=nginx.Endpoints (or
EndpointSlice) object listing all healthy Pod IPs and ports.
iptables or IPVS rules to forward traffic from the Service’s virtual
IP (ClusterIP) to one of the backend Pod IPs.CoreDNS automatically creates a DNS record for each Service:<service>.<namespace>.svc.cluster.localcurl http://my-service.default.svc.cluster.local
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
app=nginx receive traffic through ClusterIP.nginx-svc.default.svc.cluster.localhttp://nginx-svc:80.kube-proxy creates NAT rules in the nat table to redirect Service traffic.
NodeIP:NodePort (e.g. 192.168.1.11:30080)
# 1. Match NodePort traffic coming from outside
-A KUBE-NODEPORTS -p tcp --dport 30080 -m addrtype ! --src-type LOCAL \
-j KUBE-MARK-MASQ
# Mark all external traffic for SNAT (so replies go back via this node)
# 2. NodePort forwards traffic to the Service chain
-A KUBE-NODEPORTS -p tcp --dport 30080 \
-m comment --comment "default/my-service: NodePort" \
-j KUBE-SVC-XYZ123
# 3. Service chain chooses one backend Pod
-A KUBE-SVC-XYZ123 -m statistic --mode random --probability 0.5 \
-j KUBE-SEP-A1B2C3
-A KUBE-SVC-XYZ123 -j KUBE-SEP-D4E5F6
# 4. Pod DNAT rule to redirect to Pod IP:port
-A KUBE-SEP-A1B2C3 -p tcp -m tcp -j DNAT --to-destination 10.42.0.12:8080
-A KUBE-SEP-D4E5F6 -p tcp -m tcp -j DNAT --to-destination 10.42.1.7:8080
10.42.0.0/24 via 192.168.1.12 dev flannel.110.42.0.0/24 (running on Node 2) are sent through the
VXLAN interface flannel.1 to Node 2’s IP 192.168.1.12