More complex Kubernetes CronJob on Busybox

Jbn1233
1 min readApr 20, 2020

--

On the docs said…

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 from the Kubernetes cluster
restartPolicy: OnFailure

,but this is my cronjob that can not put into containers.args

wget --proxy off -T60 -q  -O - --header "Host: sample.home.net" http://192.168.1.123/job.php

The solution is just make a simple shell script and add it into configmap

apiVersion: v1
data:
wgetcron.sh: |-
#!/bin/sh
wget --proxy off -T60 -q -O - --header "Host: sample.home.net" http://192.168.1.123/job.php || true
kind: ConfigMap
metadata:
annotations:
name: mycron

Here is my Cronjob

apiVersion: v1
items:
- apiVersion: batch/v1beta1
kind: CronJob
metadata:
annotations:
name: wgetcron
namespace: default
resourceVersion: "93456931"
spec:
concurrencyPolicy: Allow
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
creationTimestamp: null
spec:
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- /extra/wgetcron.sh
image: busybox
imagePullPolicy: Always
name: standup
resources:
limits:
cpu: 100m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /extra
name: mycron
dnsPolicy: ClusterFirst
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 484
name: mycron
name: mycron

schedule: '*/1 * * * *'
successfulJobsHi

Done

--

--

Jbn1233
Jbn1233

Written by Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |

No responses yet