0

我正在做一些练习,并试图围绕如何编写 yaml 构建。

    spec:
  containers:
  - image: nginx
    imagePullPolicy: IfNotPresent
    name: nginx
    resources: {}
    envFrom: 
    - configMapRef: 
        name: anotherone # the name of the config map
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

VS

containers:
  - image: nginx
    imagePullPolicy: IfNotPresent
    name: nginx
    resources: {}
    env:
    - name: option # name of the env variable
      valueFrom:
        configMapKeyRef:
          name: options # name of config map
          key: var5 # name of the entity in config map

所以我的问题是:当我在 kubernetes 中构建时,我什么时候使用“-”符号?我确实明白,如果我在字符串之前应用'-',它会使其成为列表中的对象,但我不明白何时需要在 kubernetes 的构建中使用列表。

4

1 回答 1

2

“-”符号是因为字段类型是对象数组,如果字段类型是字符串,则值在“:”符号之后。当字段是对象时,没有“-”,而是该对象的键列表,例如您在valueFrom. 运行命令时,您将看到字段的规范化kubectl explain,例如:

 kubectl explain pod
 kubectl explain pod.spec.containers
于 2019-11-10T12:45:25.867 回答