pod 上的卷挂载为空

volume mount empty on pod

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

configmap def:

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

所有对象都创建得很好,我可以看到包含我放置的数据的配置图。但是从 config map 创建的 db.properties 文件是空的,里面没有数据。有谁知道我在这里错过了什么?

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

将您的配置映射更改为

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

这是必需的,因为您要从您的 configmap

安装特定密钥 (db.properties)