控制Pod,使Pod拥有多副本,自愈,扩缩容等能力
个人理解:
Deployment:部署,一次部署会涉及多个Pod(应用)。
1.命令方式
创建一个部署
kubectl create deployment mytomcat --image=tomcat:8.5.68
自愈能力测试
删除一个部署
# kubectl delete deploy mytomcat
查看部署信息
# kubectl get deploy
多副本部署
# kubectl create deployment my-dep --image=nginx --replicas=3
2.Yaml文件方式
多副本部署
#vi my-dep.yaml
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
- xxx
3.自愈以及故障转移
自愈:当一个pod挂了,会自动拉起
故障转移:当一个Node挂了,转移所有的Pod
3.1自愈能力测试
进入node02,手动docker stop 镜像
- 手动docker stop
- 查看pod
3.2故障转移能力测试
将Node2关机
- 关机前Pod
- 关机后(5分钟左右)
4.扩缩容
当一个应用需要再多/少部署几个副本时
4.1命令行
4.2编辑yaml ```yaml kubectl edit deployment my-depkubectl scale --replicas=5 deployment/my-dep
修改 replicas
![image.png](https://cdn.nlark.com/yuque/0/2021/png/1609516/1634721862242-5e567f23-d6a5-4fe1-99d2-18acf0537825.png#clientId=ub13c4d7d-7995-4&from=paste&height=401&id=u1d60853d&margin=%5Bobject%20Object%5D&name=image.png&originHeight=802&originWidth=1052&originalType=binary&ratio=1&size=237880&status=done&style=none&taskId=u6de90f8f-327c-47fa-88e8-c4b9055c22a&width=526)
<a name="jkO6P"></a>
# 5.滚动更新
新版本的上线是替换老版本的。不是一次性全杀死。<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1609516/1634719589156-c11cd6b6-c7db-45ce-9c1d-81d6d396820c.png#clientId=u0cb12fcb-5baf-4&from=paste&height=429&id=ucf057c11&margin=%5Bobject%20Object%5D&name=image.png&originHeight=858&originWidth=1781&originalType=binary&ratio=1&size=223648&status=done&style=none&taskId=ud2518e6b-3bd7-4304-8a4f-1cade5c77a8&width=890.5)
<a name="LKuG7"></a>
## 5.1命令行
```yaml
kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record
#查询更新状态
kubectl rollout status deployment/my-dep
5.2yaml文件
# 修改 kubectl edit deployment/my-dep
6.版本回退
#查看历史版本
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