![](/img/trans.png)
[英]How to keep a Kubernetes pod running when main process is not blocking?
[英]How to keep a process running throughout pod lifecycle?
在這種情況下,使用shareProcessNamespace: true
會有所幫助。 我們只需要通過 init 容器在后台啟動一個子進程。
這是一個例子
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: demo
name: demo
spec:
shareProcessNamespace: true
initContainers:
- name: iapp
image: nicolaka/netshoot:latest
command:
- "bash"
args:
- "-c"
- "tail -f /dev/null & echo iapp"
containers:
- name: app
image: nicolaka/netshoot:latest
command:
- "sleep"
args:
- "inifinity"
pod 運行后,當我們 exec 進入app
容器時,執行ps aux
。 我們可以看到tail -f /dev/null
仍然存在。 這證實了我們可以在整個 pod 生命周期中運行一個進程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.