I currently have a kubernetes CronJob with a concurrencyPolicy: Forbid
.
I would like to be able to uniquely identify this pod externally (k8 cluster) and internally from the pod, with an ID that will be unique forever.
I was thinking of using the creationTimestamp
and the name of the pod but unfortunately it is not that easy to pass the creationTimestamp
. Any other ideas?
Asked
Active
Viewed 130 times
0

maxisme
- 3,974
- 9
- 47
- 97
-
You can simply attach a label to the `CronJob` that you can ensure is unique. – zer0 Jul 10 '22 at 19:16
-
seems like you're giving XY problem question. you should really ask a question around what your original problem is and not around the solution you think will solve it. it will help give you better answers. anyways, i'll answer this one directly as well. – ericfossas Jul 10 '22 at 19:27
1 Answers
2
Just use the pod name like you had figured out from your other question:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
The pod name should be very unique (if you want completely unique, you'll need to grab its UID, but i'm not sure what you're trying to solve).
The pod name will be generated using the following format:
{{CRONJOB_NAME}}-{{UNIX_TIMESTAMP_IN_MINUTES}}-{{5_CHAR_RANDOM_ALPHANUM}}

ericfossas
- 1,511
- 8
- 12