我从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"
}
}]
}
}
}
}
答案 0 :(得分:22)
如果pod有超过1个容器,则需要提供特定容器的名称。
在你的情况下,有一个pod(postgres-operator-49202276-bjtf4)有2个容器(apiserver和postgres-operator)。 以下命令将提供特定容器的日志
Kubectl记录部署/ postgres-operator -c apiserver
Kubectl记录部署/ postgres-operator -c postgres-operator
答案 1 :(得分:1)
如果 pod 有多个容器,则必须给出容器名称(如上述答案中所述)。
要了解 Pod 内的所有容器,我们可以使用:
kubectl -n 获取 pods