我正在调试kubectl的日志(log)输出,其中说明:

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? 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. The JSON deployment file is as follows:

{
    "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个容器,那么您需要提供特定容器的名称.

in your case, There is a pod (postgres-operator-49202276-bjtf4) which has 2 containers (apiserver and 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

Json相关问答推荐

如何使用表键名称GROUP_BY

使用单元和非单元版本反序列化Rust中的枚举,而无需编写自定义反序列化程序

在Jenkins中使用ReadJSON读取json子元素

在ConvertFrom-Json之后需要从PowerShell对象中获取数据

组合不同属性的Jolt Spec

有没有办法让serde_json正确/不正确地处理NaN、inf和-inf(IEEE 754特殊标准)?

使用JQ将JSON输出转换为CSV复杂 struct

在Databricks中如何将JSON文件作为字典读取

将环境变量值从 yaml 传递到 json

将请求中的数据推送到数组中

如何使用 gson 调用默认反序列化

Python Flask-Restful POST 不采用 JSON 参数

如何使用 json.net 将数据表转换为 json 字符串?

如何从Typescript 中的json响应中获取日期对象

如何在不消除对象歧义的情况下使用 circe 解码 ADT

JSON 使用 simplejson 序列化 Django 模型

请求返回字节,我无法解码它们

如何使用 Jackson 的 objectMapper 反序列化接口字段?

从 JSON 中 Select 不同的值

用 JSON 编写 HTML 字符串