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?

【簡単Kubernetes】StatefulSet における `terminationGracePeriodSeconds` の設定について

Posted at

terminationGracePeriodSeconds は、Pod を終了する際に Kubernetes が「優雅なシャットダウン(graceful shutdown)」のために与える猶予時間(秒)を指定するフィールドです。


✅ 1. パラメータの定義

spec:
  template:
    spec:
      terminationGracePeriodSeconds: <秒数>
  • 意味:Pod が削除される際、Kubernetes はまず SIGTERM を送信し、この秒数の間コンテナに終了処理を行う時間を与えます。
  • 猶予時間内に終了しない場合SIGKILL が送られ、強制終了されます。

❌ 2. terminationGracePeriodSeconds: 0 は設定不可

StatefulSet(および Pod 一般)では、terminationGracePeriodSeconds0 に設定することは できません

許可されるか 説明
0 ❌ 不可 API バリデーションで拒否される
1 以上の整数 ✅ 可 正常に適用される

0 を指定すると、Kubernetes API によってエラーになります。


✅ 3. 強制終了したい場合

設定で 0 にできなくても、以下のように コマンドで強制削除 は可能です:

kubectl delete pod my-pod --grace-period=0 --force

⚠️ 本番環境では慎重に利用してください。


💡 4. 実運用でのおすすめ設定

サービスの種類や処理内容に応じて、以下のように設定すると安全です:

  • DB やキューなどの状態を持つサービス:30秒〜60秒
  • 単純な stateless API:5秒〜10秒

最小構成の例:

spec:
  template:
    spec:
      terminationGracePeriodSeconds: 5

📝 5. まとめ

  • terminationGracePeriodSeconds は Pod 終了時の優雅なシャットダウンに不可欠。
  • 0 は設定不可。最低でも 1 にする必要あり。
  • 強制終了はコマンドで可能だが、慎重に。
  • StatefulSet などの状態管理アプリでは十分な時間を確保しよう。

ご参考になれば幸いです。

0
0
1

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?