我可以在lifecycle.preStop.exec.command中使用环境变量吗?我有一个必须在preStop命令中运行的脚本。这里的答案指出,可以在postStart Can I use env in postStart command中使用env变量。但是它不适用于preStop。是错误还是我做错了什么?
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: loap
spec:
replicas: 1
template:
metadata:
labels:
app: loap
spec:
containers:
-
command:
- sh
- "-c"
- "echo $(date +%s): START >> /loap/timing; sleep 10; echo $(date +%s): END >> /loap/timing;"
image: busybox
env:
- name: secretThing
valueFrom:
secretKeyRef:
name: supersecret
key: password
lifecycle:
preStop:
exec:
command:
- sh
- "-c"
- "echo ${secretThing} $(date +%s): PRE-HOOK >> /loap/timing"
livenessProbe:
exec:
command:
- sh
- "-c"
- "echo $(date +%s): LIVENESS >> /loap/timing"
name: main
readinessProbe:
exec:
command:
- sh
- "-c"
- "echo $(date +%s): READINESS >> /loap/timing"
volumeMounts:
-
mountPath: /loap
name: timing
initContainers:
-
command:
- sh
- "-c"
- "echo $(date +%s): INIT >> /loap/timing"
image: busybox
name: init
volumeMounts:
-
mountPath: /loap
name: timing
volumes:
-
hostPath:
path: /tmp/loap
name: timing
答案 0 :(得分:0)
这在Kubernetes文档Working with objects - Names中进行了解释。
客户端提供的字符串,它引用资源URL中的对象,例如
/api/v1/pods/some-name
。给定种类的一个对象一次只能具有一个给定的名称。但是,如果删除该对象,则可以使用相同的名称创建一个新对象。
按照惯例,Kubernetes资源的名称最大长度应为253个字符,并由小写字母数字字符
-
和.
组成,但是某些资源有更具体的限制。 / p>