LoginSignup
0
0

More than 3 years have passed since last update.

AKS Deployment でアプリケーションをデプロイする Part.2

Posted at

今回は、前回デプロイした Deployment に変更を加えて見ようと思います。
前回記事 -> https://qiita.com/komiyasa/items/f9181c2f849a00d4e52b

Deployment したものの確認

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

上記の Old/New ReplicaSets: を見てみましょう。Old と New という ReplicaSet があります。これは Deployment が内部で ReplicaSet のバージョン情報を持っていることを意味しています。
New にセットされている文字が nginx-deployment-5c987f56f6 という ReplicaSet ですが、Deployment を変更するとどのようになるのか、見ていきたいと思います。

Deployment を変更する

現在のマニフェストファイルは以下のようなファイルになっています。

deploysample.yaml
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 に変更してみます。

deploysample.yaml
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

新しい Deployment があり、その Image が更新されているのが確認出来ました。

参考

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0