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

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

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

问题

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

  1. annotationexample: |
  2. [
  3. {
  4. "a": "b",
  5. "c": "d",
  6. "e": [
  7. "f"
  8. ]
  9. }
  10. ]

当我尝试使用 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:

  1. annotationexample: |
  2. [
  3. {
  4. "a": "b",
  5. "c": "d",
  6. "e": [
  7. "f"
  8. ]
  9. }
  10. ]

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

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

  1. kubectl annotate pod/example annotationexample='[
  2. {
  3. "a": "b",
  4. "c": "d",
  5. "e": [
  6. "f"
  7. ]
  8. }
  9. ]'

结果为:

  1. $ kubectl get pod example -o yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. annotations:
  6. annotationexample: |
  7. [
  8. {
  9. "a": "b",
  10. "c": "d",
  11. "e": [
  12. "f"
  13. ]
  14. }
  15. ]
  16. .
  17. .
  18. .
英文:

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:

  1. kubectl annotate pod/example annotationexample='[
  2. {
  3. "a": "b",
  4. "c": "d",
  5. "e": [
  6. "f"
  7. ]
  8. }
  9. ]
  10. '

That results in:

  1. $ kubectl get pod example -o yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. annotations:
  6. annotationexample: |
  7. [
  8. {
  9. "a": "b",
  10. "c": "d",
  11. "e": [
  12. "f"
  13. ]
  14. }
  15. ]
  16. .
  17. .
  18. .

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:

确定