pod 上的卷挂载为空

时间:2021-06-06 00:25:11

标签: kubectl configmap mounted-volumes

我正在尝试通过配置映射在 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 #

1 个答案:

答案 0 :(得分:2)

将您的配置映射更改为

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

这是必需的,因为您要从 configmap 挂载特定的密钥 (db.properties)

相关问题