当前位置: 首页 > news >正文

仿网站建设站长资源平台

仿网站建设,站长资源平台,太原网站建设开发公司,国内最大的网站制作公司deployment用于部署无状态应用 Deployment集成了上线部署、滚动升级、创建副本、回滚等功能 Deployment里包含并使用了ReplicaSet Replicaset 通过改变Pod副本数量实现Pod的扩容和缩容 参考文档 https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/deployment/ …

deployment用于部署无状态应用

Deployment集成了上线部署、滚动升级、创建副本、回滚等功能

Deployment里包含并使用了ReplicaSet

Replicaset 通过改变Pod副本数量实现Pod的扩容和缩容

参考文档 icon-default.png?t=N6B9https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/deployment/

1 yaml文件

apiVersion: apps/v1 # deployment api 版本
kind: Deployment # 资源类型为 deployment
metadata: # 元信息labels: # 标签app: nginx-deploy # 具体的 key: value 配置形式name: nginx-deploy # deployment 的名字namespace: default # 所在的命名空间,默认default
spec:replicas: 1 # 期望副本数revisionHistoryLimit: 10 # 进行滚动更新后,保留的历史版本数selector: # 选择器,用于找到匹配的 RSmatchLabels: # 按照标签匹配app: nginx-deploy # 匹配的标签key/valuestrategy: # 更新策略rollingUpdate: # 滚动更新配置maxSurge: 25% # 进行滚动更新时,更新的个数最多可以超过期望副本数的个数/比例maxUnavailable: 25% # 进行滚动更新时,最大不可用比例更新比例,表示在所有副本数中,最多可以有多少个不更新成功type: RollingUpdate # 更新类型,采用滚动更新template: # pod 模板metadata: # pod 的元信息labels: # pod 的标签app: nginx-deployspec: # pod 期望信息containers: # pod 的容器- image: nginx:1.7.9 # 镜像imagePullPolicy: IfNotPresent # 拉取策略name: nginx # 容器名称restartPolicy: Always # 重启策略terminationGracePeriodSeconds: 30 # 删除操作最多宽限多长时间

2 pod版本升级

查看帮助

[root@k8s-master1 ~]# kubectl set image -h

1, 升级前验证nginx版本

[root@k8s-master1 ~]# kubectl describe pods deploy-nginx-6d9d558bb6-f2t6r | grep Image:Image:          nginx:1.15-alpine[root@k8s-master1 ~]# kubectl exec deploy-nginx-6d9d558bb6-f2t6r -- nginx -v
nginx version: nginx/1.15.12

2, 升级为1.16版

[root@k8s-master1 ~]# kubectl set image deployment deploy-nginx nginx=nginx:1.16-alpine --record
deployment.apps/deploy-nginx image updated

说明:

  • deployment deploy-nginx代表名为deploy-nginx的deployment

  • nginx=nginx:1.16-alpine前面的nginx为容器名

  • --record 表示会记录

容器名怎么查看?

  • kubectl describe pod pod名查看

  • kubectl edit deployment deployment名来查看容器名

  • kubectl get deployment deployment名 -o yaml来查看容器名

3, 验证

如果升级的pod数量较多,则需要一定时间,可通过下面命令查看是否已经成功

[root@k8s-master1 ~]# kubectl rollout status deployment deploy-nginx  
deployment "deploy-nginx" successfully rolled out

验证 pod

[root@k8s-master1 ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
deploy-nginx-5f4749c8c8-nskp9   1/1     Running   0          104s     更新后,后面的id变了

验证版本

[root@k8s-master1 ~]# kubectl describe pod deploy-nginx-5f4749c8c8-nskp9 |grep Image:Image:          nginx:1.16-alpine             升级为1.16了[root@k8s-master1 ~]# kubectl exec deploy-nginx-5f4749c8c8-nskp9 -- nginx -v
nginx version: nginx/1.16.1                   升级为1.16了

练习: 再将nginx1升级为1.17版

[root@k8s-master1 ~]# kubectl set image deployment deploy-nginx nginx=nginx:1.17-alpine --record
deployment.apps/deploy-nginx image updated

3 pod版本回退

1, 查看版本历史信息

[root@k8s-master1 ~]# kubectl rollout history deployment deploy-nginx
deployment.apps/deploy-nginx
REVISION  CHANGE-CAUSE
1         <none>                        原1.15版
2         kubectl set image deployment deploy-nginx nginx=nginx:1.16-alpine --record=true
3         kubectl set image deployment deploy-nginx nginx=nginx:1.17-alpine --record=true

2, 定义要回退的版本(还需要执行才是真的回退版本)

[root@k8s-master1 ~]# kubectl rollout history deployment deploy-nginx --revision=1
deployment.apps/deploy-nginx with revision #1
Pod Template:Labels:       app=nginxpod-template-hash=6c9764bb69Containers:nginx:Image:      nginx:1.15-alpine       可以看到这是要回退的1.15版本Port:       80/TCPHost Port:  0/TCPEnvironment:        <none>Mounts:     <none>Volumes:      <none>

3, 执行回退

[root@k8s-master1 ~]# kubectl rollout undo deployment deploy-nginx --to-revision=1
deployment.apps/deploy-nginx rolled back

4, 验证

[root@k8s-master1 ~]# kubectl rollout history deployment deploy-nginx
deployment.apps/deploy-nginx
REVISION  CHANGE-CAUSE
2         kubectl set image deployment deploy-nginx nginx=nginx:1.16-alpine --record=true
3         kubectl set image deployment deploy-nginx nginx=nginx:1.17-alpine --record=true
4         <none>            回到了1.15版,但revision的ID变了
[root@k8s-master1 ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
deploy-nginx-6c9764bb69-zgwpj   1/1     Running   0          54s
[root@k8s-master1 ~]# kubectl describe pod deploy-nginx-6c9764bb69-zgwpj |grep Image:Image:          nginx:1.15-alpine       回到了1.15版
​
[root@k8s-master1 ~]# kubectl exec deploy-nginx-6c9764bb69-zgwpj -- nginx -v
nginx version: nginx/1.15.12            回到了1.15版

4 副本扩容

查看帮助

[root@k8s-master1 ~]# kubectl scale -h

1, 扩容为2个副本

[root@k8s-master1 ~]# kubectl scale deployment deploy-nginx --replicas=2
deployment.apps/deploy-nginx scaled

2, 查看

[root@k8s-master1 ~]# kubectl get pods -o wide
NAME                            READY   STATUS    RESTARTS   AGE   IP               NODE          NOMINATED NODE   READINESS GATES
deploy-nginx-6d9d558bb6-4c64l   1/1     Running   0          27s   10.244.159.157   k8s-master1   <none>           <none>
deploy-nginx-6d9d558bb6-hkq2b   1/1     Running   0          71s   10.244.194.95    k8s-worker1   <none>           <none>
在两个node节点上各1个pod

3, 继续扩容(我们这里只有2个node,但是可以大于node节点数据)

[root@master ~]# kubectl scale deployment deploy-nginx --replicas=4
deployment.extensions/nginx1 scaled
[root@k8s-master1 ~]# kubectl get pods -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP               NODE          NOMINATED NODE   READINESS GATES
deploy-nginx-6d9d558bb6-4c64l   1/1     Running   0          87s     10.244.159.157   k8s-master1   <none>           <none>
deploy-nginx-6d9d558bb6-586dr   1/1     Running   0          31s     10.244.135.197   k8s-master3   <none>           <none>
deploy-nginx-6d9d558bb6-hkq2b   1/1     Running   0          2m11s   10.244.194.95    k8s-worker1   <none>           <none>
deploy-nginx-6d9d558bb6-kvgsc   1/1     Running   0          31s     10.244.224.13    k8s-master2   <none>           <none>

5 副本裁减

1, 指定副本数为1进行裁减

[root@k8s-master1 ~]# kubectl scale deployment deploy-nginx --replicas=1
deployment.apps/deploy-nginx scaled

2, 查看验证

[root@k8s-master1 ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
deploy-nginx-6d9d558bb6-hkq2b   1/1     Running   0          2m56s

6 多副本滚动更新

1, 先扩容多点副本

[root@k8s-master1 ~]# kubectl scale deployment deploy-nginx --replicas=16
deployment.apps/deploy-nginx scaled

2, 验证

[root@master ~]# kubectl get pods
NAME                      READY   STATUS    RESTARTS   AGE
nginx1-7d9b8757cf-2hd48   1/1     Running   0          61s
nginx1-7d9b8757cf-5m72n   1/1     Running   0          61s
nginx1-7d9b8757cf-5w2xr   1/1     Running   0          61s
nginx1-7d9b8757cf-5wmdh   1/1     Running   0          61s
nginx1-7d9b8757cf-6szjj   1/1     Running   0          61s
nginx1-7d9b8757cf-9dgsw   1/1     Running   0          61s
nginx1-7d9b8757cf-dc7qj   1/1     Running   0          61s
nginx1-7d9b8757cf-l52pr   1/1     Running   0          61s
nginx1-7d9b8757cf-m7rt4   1/1     Running   0          26m
nginx1-7d9b8757cf-mdkj2   1/1     Running   0          61s
nginx1-7d9b8757cf-s79kp   1/1     Running   0          61s
nginx1-7d9b8757cf-shhvk   1/1     Running   0          61s
nginx1-7d9b8757cf-sv8gb   1/1     Running   0          61s
nginx1-7d9b8757cf-xbhf4   1/1     Running   0          61s
nginx1-7d9b8757cf-zgdgd   1/1     Running   0          61s
nginx1-7d9b8757cf-zzljl   1/1     Running   0          61s
nginx2-559567f789-8hstz   1/1     Running   1          114m

3, 滚动更新

[root@k8s-master1 ~]# kubectl set image deployment deploy-nginx nginx=nginx:1.17-alpine --record
deployment.apps/deploy-nginx image updated

4, 验证

[root@k8s-master1 ~]# kubectl rollout status deployment deploy-nginx
......
Waiting for deployment "deploy-nginx" rollout to finish: 13 of 16 updated replicas are available...
Waiting for deployment "deploy-nginx" rollout to finish: 14 of 16 updated replicas are available...
Waiting for deployment "deploy-nginx" rollout to finish: 15 of 16 updated replicas are available...
deployment "deploy-nginx" successfully rolled out

7 暂停更新

由于每次对 pod template 中的信息发生修改后,都会触发更新 deployment 操作

那么此时如果频繁修改信息,就会产生多次更新,而实际上只需要执行最后一次更新即可

当出现此类情况时我们就可以暂停 deployment 的 rollout

暂停更新

通过 kubectl rollout pause deployment <name> 就可以实现暂停,直到你下次恢复后才会继续进行滚动更新

此时更新配置文件后pod不会被更新,直到恢复更新

恢复更新

kubectl rollout deploy <name>

8 删除deployment

如果使用 kubectl delete deployment deploy-nginx命令删除deployment,那么里面的pod也会被自动删除

如果使用kubectl delete po po-name 命令删除deployment管理的pod,则deployment会调度重新创建pod

http://www.shuangfujiaoyu.com/news/55570.html

相关文章:

  • 怎么组建企业网站百度点击软件
  • 校园社交网站开发科学新概念seo外链平台
  • 2345天气王青岛网络优化费用
  • 公众号交易平台seo搜索引擎优化岗位要求
  • wordpress url斜杠整站关键词排名优化
  • 网站优化策划书新乡网站优化公司
  • 学校网站建设招标公告推广公司主要做什么
  • wordpress主题 芯片杭州网络推广网络优化
  • 抓取网站访客数据原理营销策略手段有哪些
  • 网站做seo多少钱个人推广app的妙招
  • 安阳网站公司哪家好成都网站seo收费标准
  • 最佳的搜索引擎网站优化推广排名
  • 玩具公司网站开发论文网络推广服务费
  • 网站建设 cn旅游seo整站优化
  • 做网站用什么ui美观市场seo是什么意思
  • wp怎么做双语网站网站的营销策略
  • 霸州做网站1766534168企业培训系统app
  • 做网站需要什么配置的笔记本今日国内新闻大事20条
  • 做网站的问卷调查全球搜官网
  • 广西住房和城乡建设厅培训中心网百度seo快速排名优化软件
  • 通用网站后台管理系统(php版)互联网营销师培训
  • 软件开发工具名词解释廊坊网站建设优化
  • 域名访问网站下简述企业网站如何推广
  • appserv做网站教程电工培训内容
  • 肥城网站建设广东今天新闻最新消息
  • app源码开发公司seo排名赚官网
  • 交通建设监理协会网站百度怎么转人工客服
  • 购物网站数据分析百度电话客服24小时人工
  • 19互动网站建设关键词优化的建议
  • 蚌埠市做网站俄罗斯搜索引擎yandex推广入口