Я пытаюсь запустить задачу из образа сервера моего приложения Rails.
Кронджоб работает один раз, но никогда не выходит.
Я протестировал на примере задания " hello world ", и это похоже на работу:
# hello-world-cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
restartPolicy: OnFailure
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-1557392100-2hnjc 0/1
Completed 0 3m
hello-1557392160-58mwb 0/1 Completed 0 2m
hello-1557392220-qbstx 0/1
send-reminders-events-starting-in-two-hours-1557391560-2qwtv 1/2 Running 0 11m
send-reminders-events-starting-in-two-hours-1557391740-9dm6q 1/2 Running 0 8m
send-reminders-events-starting-in-two-hours-1557391800-2tjdt 1/2 Running 0 8m
send-reminders-events-starting-in-two-hours-1557391860-q6qgb 1/2 Running 0 7m
send-reminders-events-starting-in-two-hours-1557391920-j9kdn 1/2 Running 0 6m
send-reminders-events-starting-in-two-hours-1557391980-sqg28 1/2 Running 0 5m
send-reminders-events-starting-in-two-hours-1557392040-twr4t 1/2 Running 0 4m
send-reminders-events-starting-in-two-hours-1557392100-skzbz 1/2 Running 0 3m
send-reminders-events-starting-in-two-hours-1557392160-2qgxl 1/2 Running 0 2m
send-reminders-events-starting-in-two-hours-1557392220-z7tk4 1/2 Running 0 1m
send-reminders-users-that-has-not-replied-1557391560-tmlnb 1/2 Running 0 11m
Это мой cronjob.yaml. Я вижу только одно эхо, потом оно висит навсегда. Есть идеи почему?
# cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: send-reminders-events-starting-in-two-hours
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
volumes:
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
containers:
- name: events-starting-in-two-hours
image: eu.gcr.io/example/pepper:latest
args:
- /bin/sh
- -c
- echo "triggering send-reminders-events-starting-in-two-hours ======="
Dockerfile
FROM ruby:2.6.2-slim-stretch
COPY Gemfile* /app/
WORKDIR /app
RUN gem update --system
RUN gem install bundler
RUN bundle install --jobs 20 --retry 5
# Set the timezone to Stockholm
ENV TZ=Europe/Stockholm
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY . /app/
RUN echo echo "RAILS_ENV is \$RAILS_ENV" >> ~/.bashrc
WORKDIR /app
CMD ["/usr/local/bundle/bin/rails", "s", "-b", "0.0.0.0", "-p", "3001"]