在卷中定义 configMap 有什么区别?

What are the differences of defining configMap in volumes?

我只是想知道 volumes 部分中这两种定义 ConfigMap 的方式有什么区别?

p.s。 test-config 包含 config.json 个文件。

newpod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: configmappod
spec:
  containers:
  - name: configmapcontainer
    image: blue
    volumeMounts:
      - name: config-vol
        mountPath: "/config/newConfig.json"
        subPath: "config.json"
        readOnly: true
  volumes:
    - name: config-vol
      projected:
        sources:
        - configMap:
            name: test-config
            items:
              - key: config.json
                path: config.json

newpod2.yaml

apiVersion: v1
kind: Pod
metadata:
  name: configmappod
spec:
  containers:
  - name: configmapcontainer
    image: blue
    volumeMounts:
      - name: config-vol
        mountPath: "/config/newConfig.json"
        subPath: "config.json"
        readOnly: true
  volumes:
    - name: config-vol
      configMap:
        name: test-config

没什么不同,它们产生相同的结果。顺便说一句,readOnly 属性是多余的,它在这两种情况下都没有任何作用。