AKS部署2:使用AKS部署应用程序

我想对上一次部署的部署进行更改和调整,下面将进行说明。
上一篇文章 -> https://qiita.com/komiyasa/items/f9181c2f849a00d4e52b

部署完成后的确认

使用kubectl describe命令,确认先前部署的桃子的详细信息。

$ kubectl describe deploy nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Fri, 22 Nov 2019 03:44:51 +0000
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
                        kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},"spec":{"replica...
Selector:               app=nginx-pod
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-pod
  Containers:
   nginx:
    Image:        nginx:1.14
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-5c987f56f6 (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  32s   deployment-controller  Scaled up replica set nginx-deployment-5c987f56f6 to 3

让我们来看一下上述的旧/新 ReplicaSets。存在着名为 Old 和 New 的 ReplicaSet。这意味着 Deployment 在内部具有 ReplicaSet 的版本信息。
New 中设置的字符是一个名为 nginx-deployment-5c987f56f6 的 ReplicaSet,但我们希望查看更改 Deployment 会发生什么情况。

改变部署

当前的清单文件变成了以下类型的文件。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment

spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-pod

  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - name: nginx
        image: nginx:1.14
        ports:
        - containerPort: 80

这个模板的镜像被定义为 image:nginx:1.14,现在我们将把它更改为1.15。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment

spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-pod

  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - name: nginx
        image: nginx:1.15
        ports:
        - containerPort: 80

一旦进行更改后,我们将使用kubectl apply命令来部署,就像上次一样。

$ kubectl apply -f Deployment/deploysample.yaml
deployment.apps/nginx-deployment configured

如果要部署已经部署的Pod等,将不会是“Created”,而是“configured”。
现在我们来确认一下详细信息。

$ kubectl describe deploy nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Fri, 22 Nov 2019 03:44:51 +0000
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 2
                        kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},"spec":{"replica...
Selector:               app=nginx-pod
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx-pod
  Containers:
   nginx:
    Image:        nginx:1.15
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-798b8d88df (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  9m4s  deployment-controller  Scaled up replica set nginx-deployment-5c987f56f6 to 3
  Normal  ScalingReplicaSet  110s  deployment-controller  Scaled up replica set nginx-deployment-798b8d88df to 1
  Normal  ScalingReplicaSet  96s   deployment-controller  Scaled down replica set nginx-deployment-5c987f56f6 to 2
  Normal  ScalingReplicaSet  96s   deployment-controller  Scaled up replica set nginx-deployment-798b8d88df to 2
  Normal  ScalingReplicaSet  82s   deployment-controller  Scaled down replica set nginx-deployment-5c987f56f6 to 1
  Normal  ScalingReplicaSet  82s   deployment-controller  Scaled up replica set nginx-deployment-798b8d88df to 3
  Normal  ScalingReplicaSet  67s   deployment-controller  Scaled down replica set nginx-deployment-5c987f56f6 to 0

查看输出结果时发现,NewReplicaSet 中的值已经变成了 nginx-deployment-798b8d88df。这表明 ReplicaSet / Pod 已经被更新,并且新的部署已经完成。执行 kubectl get replicaset 命令,确认 ReplicaSet 的详细信息。

$ kubectl get replicaset --output=wide
NAME                          DESIRED   CURRENT   READY   AGE     CONTAINERS   IMAGES       SELECTOR
nginx-deployment-5c987f56f6   0         0         0       17m     nginx        nginx:1.14   app=nginx-pod,pod-template-hash=5c987f56f6
nginx-deployment-798b8d88df   3         3         3       9m51s   nginx        nginx:1.15   app=nginx-pod,pod-template-hash=798b8d88df

我确认有一个新的部署,并且能够确认其镜像已更新。

请参考

部署

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

广告
将在 10 秒后关闭
bannerAds