lifecycle.poststart
spec.containers.lifecycle.postStart
を利用することで、コマンド実行可能- Podの起動、ENTRYPOINT、COMMANDなどと同時タイミング(非同期処理)で実行される
- 順番がある処理があるとまずい
yamlファイル
1 2 3 4 5 6 7 |
lifecycle: postStart: exec: command: - sh - -c - "echo test > /tmp/test.txt" |
app.yaml
1 2 3 4 5 6 7 8 9 10 11 12 |
<span class="na">spec</span><span class="pi">:</span> <span class="na">containers</span><span class="pi">:</span> <span class="na">image</span><span class="pi">:</span> <span class="s">apline:latest</span> <span class="na">imagePullPolicy</span><span class="pi">:</span> <span class="s">Always</span> <span class="na">tty</span><span class="pi">:</span> <span class="no">true</span> <span class="na">lifecycle</span><span class="pi">:</span> <span class="na">postStart</span><span class="pi">:</span> <span class="na">exec</span><span class="pi">:</span> <span class="na">command</span><span class="pi">:</span> <span class="pi">-</span> <span class="s">sh</span> <span class="pi">-</span> <span class="s">-c</span> <span class="pi">-</span> <span class="s2">"</span><span class="s">echo</span> <span class="s">test</span> <span class="s">></span> <span class="s">/tmp/test.txt"</span> |
出力
1 2 3 |
[root@sample-app-bc5b49978-4sr5j /]# cat /tmp/test.txt test [root@sample-app-bc5b49978-4sr5j /]# |
参考
https://qiita.com/petitviolet/items/41aa9abe106a29ba4667