kubernetes - 为什么 pod yaml 文件中的容器对象具有 "list value"而不是 "map value"

标签 kubernetes yaml containers kubernetes-pod

在 pod 创建 yaml 文件或 kubernetes 中的部署 yaml 文件中,为什么 Containers key 有一个列表值 - name: memory-demo-ctr 而不是我们可以简单地提供映射值 name: memory-demo-ctr (为什么我们提供 - 符号)?

我尝试通过网络查看但找不到解决方案。

apiVersion: v1
kind: Pod
metadata:
  name: memory-demo
  namespace: mem-example
spec:
  containers:
  - name: memory-demo-ctr
    image: polinux/stress

最佳答案

Pod 能够运行多个容器。这就是 containers 对象是列表而不是映射的原因。

kind: Pod
...
spec:
  containers:
  - name: busybox
    image: busybox:latest
  - name: nginx
    image: nginx:1.7.9
  - name: redis
    image: redis:latest

如果 containers 是一个映射对象,则无法编写配置文件来在 pod 内运行多个容器。我希望这个答案能解决您的疑问。

关于kubernetes - 为什么 pod yaml 文件中的容器对象具有 "list value"而不是 "map value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58764509/

相关文章:

kubernetes - CoreDNS 仅适用于 Kubernetes 集群中的一台主机

yaml - CloudFormation 提到架构版本 2.2 需要文档类型

mysql - 如何让服务在退出docker后仍然运行?

amazon-web-services - 在 aws-auth config-map 中使用角色

docker - 无法在共享一个只读GCE永久磁盘的1个GKE节点上运行2个Kubernetes Pod

Kubernetes - 连接被拒绝诊断

regex - 将类似正则表达式的表示法扩展到多个文字

ruby - 在我的 Rails 应用程序上运行 "heroku run rake db:migrate"时出现 YAML 语法错误

c++ - unique_ptr<int[]>、vector<int> 和 int[] 的模板化类型查找

tomcat - 我的 docker 容器 kong 以 "An invalid response was received from the upstream server"响应