我有兩個容器,一個是創建檔案,一個是洗掉它,我能夠創建檔案但不能洗掉它。我希望它每 2 小時洗掉一次檔案,我怎樣才能讓它以干凈的方式作業?我們不想使用 cron 作業...
apiVersion: v1
kind: Pod
metadata:
name: its
spec:
volumes:
- name: common
emptyDir: {}
containers:
- name: 1st
image: nginx
volumeMounts:
- name: common
mountPath: /usr/share/nginx/html
- name: 2nd
image: debian
volumeMounts:
- name: common
mountPath: /html
command: ["/bin/sh", "-c"]
args:
- while true; do
date >> /html/index.html;
sleep 7200;
done
uj5u.com熱心網友回復:
這對我有用
apiVersion: v1
kind: Pod
metadata:
name: mc1
spec:
volumes:
- name: html
emptyDir: {}
containers:
- name: 1st
image: nginx
command: ["/bin/sh", "-c"]
args:
- while true; do
touch /usr/share/nginx/html/test.txt;
ls /usr/share/nginx/html/;
echo "file created cotnainer 1";
sleep infinity;
done
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
- name: 2nd
image: debian
volumeMounts:
- name: html
mountPath: /html
command: ["/bin/sh", "-c"]
args:
- while true; do
ls /html;
rm /html/test.txt;
echo "container 2 - file removed";
ls /html;
sleep 7200;
done
我正在創建一個檔案container 1
并被container 2
您收到什么錯誤洗掉?
uj5u.com熱心網友回復:
使用帶有 alpine 基礎的 nginx 容器,您需要安裝 crond,這是一個示例:在 Alpine 容器中啟用 crond
現在,您可以在包含檔案的同一容器中運行 cron 任務,因此您只需要 1 個容器來存放 pod。
此外,這是另一個關于如何在 alpine docker 容器中運行 crond 的示例:
https://devopsheaven.com/cron/docker/alpine/linux/2017/10/30/run-cron-docker-alpine.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/470194.html
標籤:重击 亚马逊网络服务 贝壳 Kubernetes
下一篇:Kubernetespod宕機