简体   繁体   English

如何使用清单 yaml 在 Kubernetes configmap 中挂载属性文件

[英]How to mount the properties file in Kubernetes configmap using manifest yaml

I use minikube on windows 10 and try to test Kubernetes ConfigMap with both literal type and outer file type.我在 Windows 10 上使用 minikube,并尝试使用文字类型和外部文件类型测试 Kubernetes ConfigMap。 First I make below manifest yaml file to make ConfigMap.首先我在清单 yaml 文件下面制作 ConfigMap。

apiVersion: v1
kind: ConfigMap  
metadata:
  name: simple-config
data:  
  mysql_root_password: password
  mysql_password: password
  mysql_database: test

---
apiVersion: v1
kind: Pod
metadata:
  name: blog-db  
  labels:
    app: blog-mysql  
spec:
  containers:
  - name: blog-mysql
    image: mysql:latest
    env:  
      - name: MYSQL_ROOT_PASSWORD
        valueFrom: 
          configMapKeyRef:
            name: simple-config
              key: mysql_root_password
      - name: MYSQL_PASSWORD
        valueFrom: 
          configMapKeyRef:
            name: simple-config 
            key: mysql_password
      - name: MYSQL_DATABASE
        valueFrom: 
          configMapKeyRef:
            name: simple-config
            key: mysql_database
    ports:
      - containerPort: 3306

The above configmap yaml file throws no errors.上面的 configmap yaml 文件不会引发任何错误。 It works successfully.它工作成功。 This time I try to test kubernetes configmap with file.这次我尝试用文件测试 kubernetes configmap。

== configmap.properties == configmap.properties

mysql_root_password=password
mysql_password=password
mysql_database=test

But I am stuck with this part.但我被这部分困住了。 Most of configmap examples use kubectl command with --from-file option like below,大多数 configmap 示例使用带有 --from-file 选项的 kubectl 命令,如下所示,

kubectl create configmap simple-config --from-file=configmap.properties

But I have no idea how to mount the properties file using manifest yaml file grammer.但我不知道如何使用清单 yaml 文件语法挂载属性文件。 Any advice?有什么建议吗?

You can not directly mount a properties file in a pod without first creating a ConfigMap from the properties file.You can create configMap from env file as below如果不先从属性文件创建 ConfigMap,就不能直接在 pod 中挂载属性文件。您可以从 env 文件创建 configMap,如下所示

kubectl create configmap simple-config \
       --from-env-file=configmap.properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM