一、Deployment 能力
控制Pod,使Pod拥有多副本,自愈,扩缩容等能力
1、自愈&故障转移
#没有自愈能力
kubectl run mynginx --image=nginx# 自愈能力,删除pod后会重新创建
kubectl create deployment mytomcat --image=tomcat:8.5.68
2、多副本
kubectl create deployment my-dep --image=nginx --replicas=3
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: my-dep
name: my-dep
spec:
replicas: 3
selector:
matchLabels:
app: my-dep
template:
metadata:
labels:
app: my-dep
spec:
containers:
- image: nginx
name: nginx
3、 扩缩容
方式一:
kubectl scale --replicas=5 deployment/my-dep
方式二:
kubectl edit deployment my-dep
#修改 replicas
4、滚动跟新
启动一个新的,杀死一个以前的
kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record
5、版本回退
#历史记录
kubectl rollout history deployment/my-dep
#查看某个历史详情
kubectl rollout history deployment/my-dep --revision=2
#回滚(回到上次)
kubectl rollout undo deployment/my-dep
#回滚(回到指定版本)
kubectl rollout undo deployment/my-dep --to-revision=2