0

我正在尝试通过配置映射在 pod 中创建卷挂载。以下是我的定义文件:

配置图定义:

apiVersion: v1
kind: ConfigMap
metadata:
  name: firstcm
data:
  appname: springboot
  database: inmemory
  tool: h2
  type: singlecontainer

部署定义:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: firstspring
  labels:
    app: firstspring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: firstspring
  template:
    metadata:
      labels:
        app: firstspring
    spec:
      containers:
      - name: firstspring
        image: mukhou/firstspring
        volumeMounts:
          - name: firstvol
            mountPath: /etc/config/db.properties
            subPath: db.properties
      volumes:
        - name: firstvol
          configMap:
            name: firstcm

所有对象都创建得很好,我可以看到带有我放置的数据的配置图。但是从配置映射创建的 db.properties 文件是空的,里面没有数据。有谁知道我在这里想念什么?

drwxrwxrwx    2 root     root          4096 Jun  6 00:17 db.properties
/etc/config # more db.properties/
/etc/config #
4

1 回答 1

2

将您的配置映射更改为

apiVersion: v1
kind: ConfigMap
metadata:
  name: firstcm
data:
  db.properties: |
     appname: springboot
     database: inmemory
     tool: h2
     type: singlecontainer

这是必需的,因为您正在从 configmap安装特定键 ( db.properties )

于 2021-06-06T02:28:18.703 回答