我正在尝试从Rails应用程序的服务器映像运行任务。 cronjob运行一次,但是它永远不会退出。 我已经用示例“ 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获得豆荚
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"]
答案 0 :(得分:0)
我通过在CloudSQL实例上启用私有IP并从我的cronjob直接连接到该IP来解决了该问题。这样,我可以跳过cloudsql-proxy sidecar。 确保还为GKE群集启用了VPC本地支持。