在拒绝连接的情况下,继续在 Kubernetes Cron Job 上获取错误状态?
Keep getting error status on Kubernetes Cron Job with connection refused?
我正在尝试编写一个 cron 作业,该作业命中它正在拉取其映像的应用程序的其余端点。
下面是示例代码:
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .Chart.Name }}-cronjob
labels:
app: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
spec:
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 2
failedJobsHistoryLimit: 2
startingDeadlineSeconds: 1800
jobTemplate:
spec:
template:
metadata:
name: {{ .Chart.Name }}-cronjob
labels:
app: {{ .Chart.Name }}
spec:
restartPolicy: OnFailure
containers:
- name: demo
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["/bin/sh", "-c", "curl http://localhost:8080/hello"]
readinessProbe:
httpGet:
path: "/healthcheck"
port: 8081
initialDelaySeconds: 300
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 3
livenessProbe:
httpGet:
path: "/healthcheck"
port: 8081
initialDelaySeconds: 300
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 3
resources:
requests:
cpu: 200m
memory: 2Gi
limits:
cpu: 1
memory: 6Gi
schedule: "*/5 * * * *"
但我将 运行 保留为 *curl: (7) Failed to connect to localhost port 8080: Connection refused*
。
我可以从它创建容器并立即抛出的事件中看到:后退重新启动失败的容器。
我已经有 pods 运行 的演示应用程序,它工作正常,就在我试图指向这个现有应用程序并点击休息端点时,我开始 运行 进入连接拒绝错误.
查看日志时的准确输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 8080: Connection refused
事件日志:
Container image "wayfair/demo:728ac13-as_test_cron_job" already present on machine
9m49s Normal Created pod/demo-cronjob-1619108100-ndrnx Created container demo
6m17s Warning BackOff pod/demo-cronjob-1619108100-ndrnx Back-off restarting failed container
5m38s Normal SuccessfulDelete job/demo-cronjob-1619108100 Deleted pod: demo-cronjob-1619108100-ndrnx
5m38s Warning BackoffLimitExceeded job/demo-cronjob-1619108100 Job has reached the specified backoff limit
刚接触K8,大家多多指教!
您正在尝试使用您的 curl 连接到 localhost:8080
,根据我对您的 CronJob 定义的理解,这没有任何意义。
The command and arguments that you define in the configuration file
override the default command and arguments provided by the container
image. If you define args, but do not define a command, the default
command is used with your new arguments.
Note: The command field corresponds to entrypoint in some container
runtimes. Refer to the Notes below.
如果您为映像定义命令,即使映像会使用其默认入口点(或命令,取决于您使用的容器类型)在本地主机上的端口 8080 上启动休息应用程序,该命令也会覆盖入口点并且没有应用程序启动。
如果您需要启动应用程序然后执行其他操作,如 curls 等,我建议使用 .sh
脚本或类似的东西,具体取决于作业是什么 objective.
我正在尝试编写一个 cron 作业,该作业命中它正在拉取其映像的应用程序的其余端点。 下面是示例代码:
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .Chart.Name }}-cronjob
labels:
app: {{ .Release.Name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
spec:
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 2
failedJobsHistoryLimit: 2
startingDeadlineSeconds: 1800
jobTemplate:
spec:
template:
metadata:
name: {{ .Chart.Name }}-cronjob
labels:
app: {{ .Chart.Name }}
spec:
restartPolicy: OnFailure
containers:
- name: demo
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["/bin/sh", "-c", "curl http://localhost:8080/hello"]
readinessProbe:
httpGet:
path: "/healthcheck"
port: 8081
initialDelaySeconds: 300
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 3
livenessProbe:
httpGet:
path: "/healthcheck"
port: 8081
initialDelaySeconds: 300
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 3
resources:
requests:
cpu: 200m
memory: 2Gi
limits:
cpu: 1
memory: 6Gi
schedule: "*/5 * * * *"
但我将 运行 保留为 *curl: (7) Failed to connect to localhost port 8080: Connection refused*
。
我可以从它创建容器并立即抛出的事件中看到:后退重新启动失败的容器。
我已经有 pods 运行 的演示应用程序,它工作正常,就在我试图指向这个现有应用程序并点击休息端点时,我开始 运行 进入连接拒绝错误.
查看日志时的准确输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 8080: Connection refused
事件日志:
Container image "wayfair/demo:728ac13-as_test_cron_job" already present on machine
9m49s Normal Created pod/demo-cronjob-1619108100-ndrnx Created container demo
6m17s Warning BackOff pod/demo-cronjob-1619108100-ndrnx Back-off restarting failed container
5m38s Normal SuccessfulDelete job/demo-cronjob-1619108100 Deleted pod: demo-cronjob-1619108100-ndrnx
5m38s Warning BackoffLimitExceeded job/demo-cronjob-1619108100 Job has reached the specified backoff limit
刚接触K8,大家多多指教!
您正在尝试使用您的 curl 连接到 localhost:8080
,根据我对您的 CronJob 定义的理解,这没有任何意义。
The command and arguments that you define in the configuration file override the default command and arguments provided by the container image. If you define args, but do not define a command, the default command is used with your new arguments.
Note: The command field corresponds to entrypoint in some container runtimes. Refer to the Notes below.
如果您为映像定义命令,即使映像会使用其默认入口点(或命令,取决于您使用的容器类型)在本地主机上的端口 8080 上启动休息应用程序,该命令也会覆盖入口点并且没有应用程序启动。
如果您需要启动应用程序然后执行其他操作,如 curls 等,我建议使用 .sh
脚本或类似的东西,具体取决于作业是什么 objective.