英文:
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"
]
}
]
.
.
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论