Issue
I want to create a crone in the cluster which should have access to all of the namespaces, I don't want to configure that job in each and every namespace as I have multiple namespaces. Is this possible? Edit: I want to run same cronjob in all namespace
Solution
You can use helm to achieve this, either static namespaces or dynamic all namespaces.
{{- range $namespaces := .Values.namespaces }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
namespace: {{ $namespaces }}
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
---
{{- end }}
and values file
namespaces:
- namesapce-1
- namesapce-2
Dynamic namespaces:
helm install my-cronjob helm-chart --set "namespaces={$(k get ns | awk 'BEGIN{ORS=","} { if (NR>1) print $1}')}"
A complete working example multi-namespace-deployment
Answered By - Adiii Answer Checked By - Cary Denson (WPSolving Admin)