[英]kubectl patch deployment date return error
When I try当我尝试
kubectl patch deployment my-node-app -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"
date +'%s' \"}}}}}" -n my-namespace
kubectl patch deployment my-node-app -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"
date + '%s' \"}}}}}" -n my-namespace
I get below error:我得到以下错误:
The Deployment "my-node-app" is invalid: spec.template.labels: Invalid value: "
date +'%s' ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (eg 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
The Deployment "my-node-app" is invalid: spec.template.labels: Invalid value: "
date +'%s' ": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (eg 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
What am I missing in my code?我的代码中缺少什么?
apiVersion: apps/v1
kind: Deployment
metadata:
name: node
namespace: dev
labels:
app: my-node-app
spec:
replicas: 2
selector:
matchLabels:
app: my-node-app
template:
metadata:
labels:
app: my-node-app
spec:
hostNetwork: true
securityContext:
fsGroup: 1000
containers:
- name: node
imagePullPolicy: Always
image: gcr.io/my-repo/my-node-app:latest
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: my-configmap
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 2
memory: 8Gi
restartPolicy: Always
You can try to echo your json string:您可以尝试回显您的 json 字符串:
echo "{"spec":{"template":{"metadata":{"labels":{"date":"date +'%s'"}}}}}"
-> {spec:{template:{metadata:{labels:{date:date +%s}}}}}
In your case, you want to execute the date command, so:在你的情况下,你想执行 date 命令,所以:
echo "{"spec":{"template":{"metadata":{"labels":{"date":"$(date +'%s')"}}}}}"
-> {spec:{template:{metadata:{labels:{date:1594299081}}}}}
even better, you should wrap the json string in simple quotes:更好的是,您应该将 json 字符串用简单的引号括起来:
echo '{"spec":{"template":{"metadata":{"labels":{"date":"'$(date +'%s')'"}}}}}'
-> {"spec":{"template":{"metadata":{"labels":{"date":"1594299282"}}}}}
Also, you don't really need quotes for date +%s
此外,您真的不需要
date +%s
引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.