当创建一个Deployment时,也会ReplicaSet也会创建,pod是由Deployment和ReplicaSet共同管理的。
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deploy
spec:
selector:
matchLabels:
app: test-deploy
template:
metadata:
labels:
app: test-deploy
spec:
containers:
- name: test-deploy
image: luksa/kubia
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 8080
滚动升级
当修改镜像版本之后,Deployment会自动进行滚动升级。
回滚
kubectl rollout undo deployment deploymentname
查看滚动升级历史
kubectl rollout history deployment deploymentname
控制滚动速率
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
maxSurge是在预期数目中滚动升级时,最多可以比预期数目的pod多的数量
maxUnavailable是预期数目中的pod有多少不可用的,不可用的pod不能超过maxUnavailable
暂停滚动升级
kubectl rollout pause deployment deploymentname
恢复滚动升级
kubectl rollout resume deployment deploymentname
组织出错版本的滚动升级
在yaml文件中添加就绪探针和minReadySeconds
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deploy
spec:
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: test-deploy
template:
metadata:
labels:
app: test-deploy
spec:
containers:
- name: test-deploy
image: luksa/kubia
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 10
增加就绪探针之后,在就绪探针返回之前并不会将这个pod添加到服务中去,直到就绪探针探测成功至指定的次数之后,然后再等待minReadySeconds才作为正常的服务使用。