1
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 1 year has passed since last update.

退勤時間にPodを自動削除する方法⏰

Posted at

Kubernetes環境で、毎日18時にPodを自動的に削除したい場合は、コマンドに以下のものを使用します。この方法では、スクリプトが指定された時間まで待機し、その後Podを終了させます。

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: your-image
    command: ["bash", "-c"]
    args:
      - 'while [ "$(TZ=Asia/Tokyo date +%H%M)" != "1900" ]; do sleep 60; done'

設定の説明

  • command: ["bash", "-c"]
    この設定は、Bashシェルを使用してコマンドを実行することを指定します。

  • args:
    以下のコマンドを引数として渡します。

    while [ "$(TZ=Asia/Tokyo date +%H%M)" != "1900" ]; do sleep 60; done
    

    このスクリプトは、東京時間で19時になるまでループし、1分間隔で時刻をチェックします。19時になるとループを終了し、コンテナが終了します。

終わり

これで消し忘れがなくなってハッピー

1
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
1
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?