简体   繁体   English

Kubernetes / kubectl - “必须指定容器名称”,但似乎是这样?

[英]Kubernetes / kubectl - “A container name must be specified” but seems like it is?

I'm debugging log output from kubectl that states:我正在调试 kubectl 的日志输出,其中指出:

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

OK, so that's an explanatory error message, but looking at my JSON template it ought to just create both containers specified, correct?好的,这是一条解释性错误消息,但查看我的 JSON 模板,它应该只创建指定的两个容器,对吗? What am I missing?我错过了什么? (please forgive my ignorance.) (请原谅我的无知。)

I'm using just a standard kubectl create -f command to create the JSON file within a shell script.我只使用标准的 kubectl create -f 命令在 shell 脚本中创建 JSON 文件。 The JSON deployment file is as follows: 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"
                    }
                }]
            }
        }
    }
}

If a pod has more than 1 containers then you need to provide the name of the specific container.如果一个 pod 有 1 个以上的容器,那么您需要提供特定容器的名称。

in your case, There is a pod (postgres-operator-49202276-bjtf4) which has 2 containers (apiserver and postgres-operator ).在您的情况下,有一个 pod (postgres-operator-49202276-bjtf4),它有 2 个容器(apiserver 和 postgres-operator)。 following commands will provide logs for the specific containers以下命令将为特定容器提供日志

kubectl logs deployment/postgres-operator -c apiserver


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

A container name must be given if the pod is having more than one containers (as mentioned in above answers).如果 pod 有多个容器,则必须给出容器名称(如上述答案中所述)。

To know all the containers inside a pod we can use:要了解 Pod 内的所有容器,我们可以使用:

kubectl -n get pods <POD_NAME> -o jsonpath="{..image}" kubectl -n 获取 pods <POD_NAME> -o jsonpath="{..image}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM