如何使用kubectl编辑带有非字母数字字符的Pod注释。

huangapple go评论59阅读模式
英文:

how to edit annotations of pod with non-alphanumeric characters using kubectl

问题

我有一个 Pod,我想要为其插入以下注释:

annotationexample: |
      [
        {
          "a": "b",
          "c": "d",
          "e": [
            "f"
          ]
        }
      ]      

当我尝试使用 kubectl annotate --overwrite 应用时,我收到一个错误,错误消息是 name part must consist of alphanumeric characters, '-', '_', or '.', and must start and end with an alphanumeric character[, ], {} 字符引起了问题,但我以前可以通过 Helm Chart 应用该注释。但我正在寻求仅使用 kubectl 来编辑注释的解决方案。我不想从 YAML 文件中创建一个新的 Pod(kubectl apply -f),因为这会添加额外的字段。

英文:

I have a pod which I want to insert the following annotation for:

annotationexample: |
      [
        {
          "a": "b",
          "c": "d",
          "e": [
            "f"
          ]
        }
      ]

When I try to apply this using kubectl annotate --overwrite I get an error saying name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character. The [, ], { and } characters are causing issues, but I have previously been able to apply the annotation through a helm chart. But I am seeking a solution through just using kubectl to only edit annotations. I don't want to create a new pod from a yaml file (kubectl apply -f) as then extra fields are added.

答案1

得分: 1

看起来你的命令行中有一个错误。如果你想在一个资源上设置该注解,你可以运行如下命令:

kubectl annotate pod/example annotationexample='[
  {
    "a": "b",
    "c": "d",
    "e": [
      "f"
    ]
  }
]'

结果为:

$ kubectl get pod example -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    annotationexample: |
      [
        {
          "a": "b",
          "c": "d",
          "e": [
            "f"
          ]
        }
      ]
.
.
.
英文:

It sounds like you have an error in your command line. If you want to set that annotation on a resource, you would run a command like this:

kubectl annotate pod/example annotationexample='[
  {
    "a": "b",
    "c": "d",
    "e": [
      "f"
    ]
  }
]
'

That results in:

$ kubectl get pod example -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    annotationexample: |
      [
        {
          "a": "b",
          "c": "d",
          "e": [
            "f"
          ]
        }
      ]
.
.
.

huangapple
  • 本文由 发表于 2023年7月13日 19:21:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678800.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定