|NO.Z.00134|——————————|CloudNative|——|KuberNetes&资源调度.V04|——|deployment.v02|更新|

一、Deployment更新
### --- 修改deployment配置参数,触发更新
~~~     修改配置参数,触发更新
~~~     只有更改了spec中的template的配置才会触发它的更新。才会新生成一个RS,
~~~     更改了template才会记录一个新的RS,

[root@k8s-master01 ~]# vim nginx-deploy.yaml
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx 

二、使用kubectl命令去生成一个新的RS

### --- 更新容器的镜像版本nginx:1.15.3。

[root@k8s-master01 ~]# kubectl get deploy -oyaml |grep image                        //查看当前使用的镜像
                  f:image: {}
                  f:imagePullPolicy: {}
        - image: nginx:1.15.2                                                       //把镜像版本改为1.15.3
          imagePullPolicy: IfNotPresent
### --- 更新它的镜像版本

[root@k8s-master01 ~]# kubectl set image deploy nginx nginx=nginx:1.15.3 --record   // --record可以查看之前更改的参数
deployment.apps/nginx image updated
### --- 查看创建的pod

[root@k8s-master01 ~]# kubectl get po
NAME                     READY   STATUS              RESTARTS   AGE
nginx-5dfc8689c6-ps42t   0/1     ContainerCreating   0          25s 
### --- 查看它滚动更新的过程
~~~     首先它会启动一个新的RS,它会把它的副本数量设置为1,等待它起来之后它会把旧的删除一个,
~~~     删除掉之后,它会再启动一个新的。

[root@k8s-master01 ~]# kubectl rollout status deploy nginx              
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
deployment "nginx" successfully rolled out
三、deployment滚动更新
### --- 当然你启动几个新的,删除旧的的策略是在滚动发布的策略中定义的

[root@k8s-master01 ~]# vim nginx-deploy.yaml                                        //是在这个位置定义的;滚动发布的策略不止这一个。
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate 
### --- 一个新的replicas被更新了

[root@k8s-master01 ~]# kubectl get rs                                   
[root@k8s-master01 ~]# kubectl get rs
nginx-66bbc9fdc5   1         1         1       164m
### --- 查看是是否有新的rs被创建

[root@k8s-master01 ~]# kubectl get po
NAME                     READY   STATUS              RESTARTS   AGE
nginx-5dfc8689c6-ps42t   1/1     Running             0          3m15s
nginx-5dfc8689c6-tsxcp   0/1     ContainerCreating   0          2m39s
nginx-66bbc9fdc5-v6687   1/1     Running             0          19m
### --- 查看pod的镜像版本

[root@k8s-master01 ~]# kubectl get po nginx-5dfc8689c6-tsxcp -oyaml |grep image
            f:image: {}
            f:imagePullPolicy: {}
  - image: nginx:1.15.3                         // 可以看到它的镜像已经被改为1.15.3
    imagePullPolicy: IfNotPresent
    image: nginx:1.15.3
    imageID: docker-pullable://nginx@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
四、更新deployment的镜像版本
### --- 更新容器的镜像版本nginx:1.15.4。

[root@k8s-master01 ~]# kubectl set image deploy nginx nginx=nginx:1.15.4 --record
deployment.apps/nginx image updated 
### --- 查看deployment创建记录

[root@k8s-master01 ~]# kubectl describe deploy 
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  29m    deployment-controller  Scaled up replica set nginx-66bbc9fdc5 to 2
  Normal  ScalingReplicaSet  13m    deployment-controller  Scaled up replica set nginx-5dfc8689c6 to 1
  Normal  ScalingReplicaSet  12m    deployment-controller  Scaled down replica set nginx-66bbc9fdc5 to 1
  Normal  ScalingReplicaSet  12m    deployment-controller  Scaled up replica set nginx-5dfc8689c6 to 2
  Normal  ScalingReplicaSet  8m58s  deployment-controller  Scaled down replica set nginx-66bbc9fdc5 to 0
  Normal  ScalingReplicaSet  33s    deployment-controller  Scaled up replica set nginx-6cdd5dd489 to 1      // 创建了一个新的replica
### --- 查看创建的pod

[root@k8s-master01 ~]# kubectl get po
NAME                     READY   STATUS              RESTARTS   AGE
nginx-6cdd5dd489-sfdzr   0/1     ContainerCreating   0          13s     // nginx-6cdd5dd489-sfdzr和上面最后一条对应上了
### --- 它会启动一个RS,把它的副本数量设置为1.

[root@k8s-master01 ~]# kubectl describe deploy
  Type    Reason             Age    From                   Message
  Normal  ScalingReplicaSet  83s    deployment-controller  Scaled up replica set nginx-6cdd5dd489 to 2
  Normal  ScalingReplicaSet  44s    deployment-controller  Scaled down replica set nginx-5dfc8689c6 to 0 
### --- 查看RS的记录

[root@k8s-master01 ~]# kubectl get rs                                   
NAME               DESIRED   CURRENT   READY   AGE
nginx-5dfc8689c6   0         0         0       17m
nginx-66bbc9fdc5   0         0         0       179m
nginx-6cdd5dd489   2         2         2       5m18s
### --- 查看创建的rs的yaml查看两次的镜像版本
~~~     升级的时候一般都是使用edit或者修改它的创建yaml文件,
~~~     然后执行replace。发版的时候会使用set命令去做。

[root@k8s-master01 ~]# kubectl get rs nginx-5dfc8689c6 -oyaml 
    spec:
      containers:
      - image: nginx:1.15.3                 // 之前的是1.15.3
[root@k8s-master01 ~]# kubectl get rs nginx-6cdd5dd489  -oyaml
    spec:
      containers:
      - image: nginx:1.15.4                 // 而新的这个是1.15.4
        imagePullPolicy: IfNotPresent
        name: nginx

 

 

 

 

 

 

 

 

 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(26)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示