gpt4 book ai didi

json - Kubernetes/kubectl - "A container name must be specified"但似乎是这样?

转载 作者:行者123 更新时间:2023-12-03 12:11:05 29 4
gpt4 key购买 nike

我正在调试 kubectl 的日志输出,其中指出:

Error from server (BadRequest): a container name must be specified for pod postgres-operator-49202276-bjtf4, choose one of: [apiserver postgres-operator]

好的,这是一条解释性错误消息,但是查看我的 JSON 模板,它应该只创建指定的两个容器,对吗?我错过了什么? (请原谅我的无知。)

我只使用标准的 kubectl create -f 命令在 shell 脚本中创建 JSON 文件。 JSON部署文件如下:
{
"apiVersion": "extensions/v1beta1",
"kind": "Deployment",
"metadata": {
"name": "postgres-operator"
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"labels": {
"name": "postgres-operator"
}
},
"spec": {
"containers": [{
"name": "apiserver",
"image": "$CCP_IMAGE_PREFIX/apiserver:$CO_IMAGE_TAG",
"imagePullPolicy": "IfNotPresent",
"env": [{
"name": "DEBUG",
"value": "true"
}],
"volumeMounts": [{
"mountPath": "/config",
"name": "apiserver-conf",
"readOnly": true
}, {
"mountPath": "/operator-conf",
"name": "operator-conf",
"readOnly": true
}]
}, {
"name": "postgres-operator",
"image": "$CCP_IMAGE_PREFIX/postgres-operator:$CO_IMAGE_TAG",
"imagePullPolicy": "IfNotPresent",
"env": [{
"name": "DEBUG",
"value": "true"
}, {
"name": "NAMESPACE",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.namespace"
}
}
}, {
"name": "MY_POD_NAME",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.name"
}
}
}],
"volumeMounts": [{
"mountPath": "/operator-conf",
"name": "operator-conf",
"readOnly": true
}]
}],
"volumes": [{
"name": "operator-conf",
"configMap": {
"name": "operator-conf"
}
}, {
"name": "apiserver-conf",
"configMap": {
"name": "apiserver-conf"
}
}]
}
}
}
}

最佳答案

如果一个 pod 有 1 个以上的容器,那么您需要提供特定容器的名称。

在您的情况下,有一个 pod (postgres-operator-49202276-bjtf4),它有 2 个容器(apiserver 和 postgres-operator)。
以下命令将为特定容器提供日志

kubectl logs deployment/postgres-operator -c apiserver


kubectl logs deployment/postgres-operator -c postgres-operator

关于json - Kubernetes/kubectl - "A container name must be specified"但似乎是这样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47129376/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com