I’ve pod with two containers, one is creating a file and one delete it, I was able to create the file but not to delete it. I want it to delete the files every 2 hours, how can I make it work in clean way? we dont want to use cron job…
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
2
Answers
Using nginx container with an alpine base you need to install crond, here is an example: Enable crond in an Alpine container
Now, you could run a cron task in the same container that has the files so you just need 1 container for the pod.
Also, here is another example on how to run crond in an alpine docker container:
https://devopsheaven.com/cron/docker/alpine/linux/2017/10/30/run-cron-docker-alpine.html
This is what works for me
i am creating a file from
container 1
and getting removed bycontainer 2
what error are you getting?