简体   繁体   English

kubectl 补丁部署日期返回错误

[英]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.

相关问题 如何使用 kubectl 在部署中修补容器环境变量? - How to patch container env variable in deployment with kubectl? Kubernetes:错误的kubectl编辑部署 - Kubernetes: Error kubectl edit deployment 如何利用 kubectl 补丁部署来更新环境变量? - How to leverage kubectl patch deployment to update an environment variable? 使用“ kubectl补丁”更新部署标签不起作用 - Update deployment labels using “kubectl patch” does not work 如何使用 kubectl Patch 命令删除 Deployment volumeMounts 中的元素? - How can i remove an element in Deployment volumeMounts with kubectl Patch command? 部署到gcloud上的CircleCI kubectl配置错误 - CircleCI kubectl config error on deployment to gcloud Kubernetes (OpenShift) 👉 kubectl (oc - OpenShift CLI) `patch` 返回错误:无法将数组解组为 map[string]interface {} 类型的 Go 值 - Kubernetes (OpenShift) 👉 kubectl (oc - OpenShift CLI) `patch` return the error: cannot unmarshal array into Go value of type map[string]interface {} Kubectl 补丁错误:不包含声明的合并键:名称 - Kubectl Patch Error: does not contain declared merge key: name 如何在执行 kubectl patch 命令时修复 json 解组错误? - How to fix json unmarshal error while executing kubectl patch command? kubectl 运行覆盖节点选择器:错误:无效的 JSON 补丁 - kubectl run override nodeselctor: error: Invalid JSON Patch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM