Using kubectl to run a Kubernetes job with command line arguments.
1 – Create a secret with the command line arguments:
kubectl create secret generic job-args --from-literal=version="17.43.12"
The above command creates a temporary secret called job-args with and argument called version.
2 – The following yml represents a kubernetes job (job.yml) that can be used with the given arguments:
apiVersion: batch/v1
kind: Job
metadata:
name: job-with-args
spec:
template:
spec:
containers:
- name: job-container
image: alpine:latest
imagePullPolicy: IfNotPresent
env:
- name: VERSION
valueFrom:
secretKeyRef:
name: job-args
key: version
command:
- /bin/sh
- -c
args:
- |-
my-command-that-needs-args "$(VERSION)"
3 – The next step is to run the job:
kubectl create -f job.yml
4 – If you need to observe logs, the following command might be useful:
kubectl logs job/job-with-args --follow --pod-running-timeout=20s
Deixe um comentário