Wellcome to SuperUser.
First of all, maybe you're facing it the wrong way. If the goal is to restart the complete container every 15 minutes, maybe you should check the links bellow.
Question about restarting pods with multiple possible solutions
Pod lifecycle documentation
Kubernetes concepts - Explanation about how kubernetes works and the names people uses for things there.
Just for completity, and in case you actually want to run a periodic task, check specific Kubernetes docs, they state how to create cronjobs and debug them. I'd also suggest to read about Kubernetes limitations in documentation, as there may be something actively preventing to run your cronjobs
GCP Documentation about cronjobs
Kubernetes documentation about Cronjobs
I'm giving you a resume about how to create a cronjob task, but you should carefully read the above if you're not familiar with kubernetes and follow the links inside, they've environments ready to play and learn the basics of kubernetes.
It is more elaborated inside, but it basically gives you an example command and the way to deploy it. I've modified it to be once every 15 minutes and run a pkill. You've to create a yaml file with the following contents (check syntax for more complex cron behaviours):
# cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/15 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- pkill yourprocess
restartPolicy: OnFailure
and then deploy it using
kubectl apply -f [FILENAME]
Use the following command to check if your cronjob was deployed:
kubectl describe cronjob [CRON_JOB]
Post describing the above processes with more screenshots and examples
After this point this is a very generic answer. You can post comments and I'll try to help you out, but I currently have no access to an Alpine Linux installation, so I may not be helpful. This is the Alpine Linux documentation page addressing your issue
Tracing your error: The simple way
There's a very simple way to narrow down whats going out, although it is not very precise. There are two chances here: There's a problem with CRON itself, or you have a problem with your script (permissions, for instance). The process is simple:
- Create a task that creates an empty file inside a folder where you're ABSOLUTLY SURE everyone can read and write.
- If the new file appears when the task is suposed to run, it means that your cron is executing properly and that you have a problem with your script. Go to "Script problems" section. If not, you've a problem with cron. Go to Cron problems section
Tracing your error: Logs
The best way to solve problems in any system is looking at the logs. Software like cron normally stores logs on syslog (normally located at /var/log/syslog), unless configured otherwise. This post speaks about cron logging folders.
If you find out where your cron instance is logging and there's nothing there, it means that your cron service is not running at all. There's a Alpine Linux specific solution for this problem in Cron problems. If you can see errors, you should look at them and try to narrow down your problem. If not, you should make sure that your script is actually not running.
Cron problems
Ok, now you know cron is not working properly. There are various possible scenarios:
- Cron is not running at all
Maybe the cron service is not started. Check if the service is running. If it is not, try to start it manually. Check if it has started properly and then add it to startup process. The way to do so varies depending on the OS. In Alpine Linux, this should do the trick:
rc-service crond start && rc-update add crond
- The cron folder you're using is not being used by cron
You should check the main cron config file in order to verify that the folder you're putting scripts on is actually added.
Maybe the config line has some error with spaces on arguments or things like that, although in this case this seem not to be the scenario, as you used test commands on your folder.
Script problems
If your script runs but it is not producing the desired output, it is a good idea to perform the following steps:
- Separate your script into a file. Give it run permissions and ensure that the first line properly states the shell to use, in Alpine's case, this line should be #!/bin/sh
- Redirect the standard and error output to a file to analize what's going on.
General suggestions
- As stated in Script problems section, it is a good practise to separate your oneliners into script files and point their output to files, in order to be able to debug problems of all kinds.
- Take a close look at directory and file permissions (those directly accesed by your script and those that cron should read / user in order to execute your scripts), it is a common cause of failure, specially in containers.
EDIT: Maybe I understood your situation in the wrong way and you're in an scenario like this one