优雅热更新
更新时考虑的问题
更新 pod 时,service endpoint 是如何变化的,kube-proxy 做了什么?
答:StatefulSet、Deployent, Rc 等在更新时,等 pod 状态状态变为 ready 之后,再更新与之关系的 service endpoint, 然后 kube-proxy 再更新iptables/ipvs规则。
更新 pod 时,pod 是否已经完全启动并且可以正常处理流量?还有在 pod销毁时又怎么保证 pod 处理完已连接的流量?该如何做呢?
答:Pod 的探针 readiness 和 liveness 会在启动和运行中确保 pod 状态ready 可以处理流量。销毁之前把 pod prestop 等待几十秒的时间确保 pod 处理完流量。
最佳实践 yaml 示例
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
component: nginx
template:
metadata:
labels:
component: nginx
spec:
containers:
- name: nginx
image: "nginx"
ports:
- name: http
hostPort: 80
containerPort: 80
protocol: TCP
readinessProbe:
httpGet:
path: /healthz
port: 80
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 15
timeoutSeconds: 1
lifecycle:
preStop:
exec:
command: ["/bin/bash", "-c", "sleep 30"]
参考
Last updated
Was this helpful?