0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rolling Update vs Recreate

Posted at

DeploymentやDaemonSetsはPODアップデートの戦略(Strategy)を指定できる。

指定できる戦略の代表は下記の二つ

  • Recreate
  • RollingUpdate

Recreate

ReplicaSet一度すべてのPODを削除してから再度PODを作成しアップデートする。
この方法ではダウンタイムが発生する。

  • メリット:
    ReplicaSet内のすべてのPODを削除したのちに再度PODを作成するので、
    限られたリソースでもアップデート可能。
    また、RollingUpdateと比較して高速。
  • デメリット:すべてのPODが一度削除されるのでダウンタイムが生じる
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  strategy:
    type: Recreate
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

specにてStrategyを指定する。type以外に設定項目はない。

RollingUpdate

ReplicaSetを2つ用意し、PODの一部ずつアップデートを実施できる。

  • メリット:
    ダウンタイムが生じない。
  • デメリット:
    アップデートに稼働リソース以上のリソースが必要
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnaveilable: 0
      maxSurge: 1
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

maxUnavailabelはアップデート中に許容できる不足POD数を指定できる。
maxSuegeは超過できるPOD数を指定できる。
上のマニュフェストではPODの1つまで不足と0つの超過を許容している。

上のマニュフェストでのRollingUpdateのReplicaSetの推移の例

Old ReplicaSet New ReplicaSet
3 0
2 0
2 1
1 1
1 2
0 3
maxUnavailable: 25%
maxSurge: 25%

maxUnavailabelとmaxSuegeは%で指定することが可能

ロールバック

Deploymentはロールバックをすることができる。
リヴィジョンはロールアウト時にPODの.spec.template変更されたときに記録される。

ロールバックの実行
--to-revisionで特定のリヴィジョンを指定できる

kubectl rollout undo deployment/sample

ロールアウトのステータスの確認

kubectl rollout status deployment/sample

ロールアウトの履歴を確認

kubectl rollout history deployment/sample

参考文献

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?