5
2

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.

KubernetesのDockerコンテナを再起動する方法

Last updated at Posted at 2019-12-20

時々忘れてしまいますが、KubernetesのDockerコンテナを再起動する方法はないです。
kubectl scale deploymentのreplica数を0にし、また元の数に戻すやり方を使います。

  • replicaの数を0にする
kubectl scale deployment [Deployment Name] --replicas=0 -n [Namespace]
deployment.extensions/[Deployment Name] scaled
  • podの数が0になっていることを確認
kubectl get pods -n  [Namespace]
No resources found.
  • replicaの数を1にする
kubectl scale deployment [Deployment Name] --replicas=1 -n [Namespace]
deployment.extensions/[Deployment Name] scaled
  • podの数が1になっていることを確認
kubectl get pods -n  [Namespace]
NAME                   READY     STATUS    RESTARTS   AGE
[Deployment Name-ID]   1/1       Running   0          64s

追記(2020.1.28)

Kubernetes Ver.1.15から、Deploymentリソースに関してrollout restartで再起動が出来るようになりました。使い方は以下です。

kubectl rollout restart deployments/[Name] --n [Namespace]

Describeしてみると、restartコマンドの中身はScale down->Scale upであることが分かります。

  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  13s   deployment-controller  Scaled up replica set [Deployment Name-ID]  to 1
  Normal  ScalingReplicaSet  12s   deployment-controller  Scaled down replica set [Deployment Name-ID]  to 0
5
2
2

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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?