Skip to content

Instantly share code, notes, and snippets.

@dawncold
Created May 12, 2021 23:33
Show Gist options
  • Save dawncold/2c90bc83ac5b674edb35ac7de11addbc to your computer and use it in GitHub Desktop.
Save dawncold/2c90bc83ac5b674edb35ac7de11addbc to your computer and use it in GitHub Desktop.
k8s secret and cronjob
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
stringData:
dbconnstr: this-is-db-connection-string-in-secret
username: admin
password: KuBeRnEtEs
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
env:
- name: DBCONNECTIONSTRING
valueFrom:
secretKeyRef:
name: app-secret
key: dbconnstr
- name: USERNAME
valueFrom:
secretKeyRef:
name: app-secret
key: username
- name: PASSWORD
valueFrom:
secretKeyRef:
name: app-secret
key: password
command:
- /bin/sh
- -c
- date; echo db:$DBCONNECTIONSTRING user:$USERNAME pass:$PASSWORD
restartPolicy: OnFailure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment