3
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 3 years have passed since last update.

kubernetesでPod起動時にコマンドを実行する

Posted at

lifecycle.poststart

  • spec.containers.lifecycle.postStartを利用することで、コマンド実行可能
  • Podの起動、ENTRYPOINT、COMMANDなどと同時タイミング(非同期処理)で実行される
    • 順番がある処理があるとまずい

yamlファイル

        lifecycle:
          postStart:
            exec:
              command:
                - sh
                - -c
                - "echo test > /tmp/test.txt"
app.yaml
    spec:
      containers:
        image: apline:latest
        imagePullPolicy: Always
        tty: true
        lifecycle:
          postStart:
            exec:
              command:
                - sh
                - -c
                - "echo test > /tmp/test.txt"

出力

[root@sample-app-bc5b49978-4sr5j /]# cat /tmp/test.txt 
test
[root@sample-app-bc5b49978-4sr5j /]# 

参考

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