k8s配置configmap指定到容器的指定文件

我们需要将名称为walletkey.properties的文件做成configmap,然后将walletkey.properties文件单独挂载出来到/data/walletkey.properties,且不能覆盖/data目录,具体如下

1、创建configmap

configmap文件内容

其中walletkey.properties: >-引用部分是文本内容

yaml 复制代码
---
apiVersion: v1
data:
  walletkey.properties: >-
    wallet.keys.data[0].coin=bnb

    wallet.keys.data[0].seed=abcdedfefeds

    wallet.keys.data[0].type=eth


    wallet.keys.data[1].coin=arb

    wallet.keys.data[1].seed=abcdedfefeds

    wallet.keys.data[1].type=eth



    wallet.keys.data[2].coin=op

    wallet.keys.data[2].seed=abcdedfefeds

    wallet.keys.data[2].type=eth



    wallet.keys.data[3].coin=matic

    wallet.keys.data[3].seed=abcdedfefeds

    wallet.keys.data[3].type=eth


    wallet.keys.data[4].coin=sol

    wallet.keys.data[4].seed=abcdedfefeds

    wallet.keys.data[4].type=sol


    wallet.keys.data[5].coin=btc

    wallet.keys.data[5].seed=abcdedfefeds

    wallet.keys.data[5].type=btc
kind: ConfigMap
metadata:
  name: walletkey.properties
  namespace: bitget
  resourceVersion: '4866437'

创建configmap

handlebars 复制代码
kubectl create -f configmap.yaml

查看创建好的configmap

handlebars 复制代码
kubectl get configmap walletkey.properties -n bitget

2、挂载操作

A方案、yaml配置

配置文件内容如下

handlebars 复制代码
          volumeMounts:
            - mountPath: /data/walletkey.properties
              name: volume-h77am
              readOnly: true
              subPath: walletkey.properties
      volumes:
        - configMap:
            defaultMode: 420
            items:
              - key: walletkey.properties
                path: walletkey.properties
            name: walletkey.properties
          name: volume-h77am

B方案、kuboard控制台操作

3、进入容器后我们可以看到我们的文本内容

handlebars 复制代码
root@wallet-597c57d89c-z6hvz:/data# ls /data/
data  logs  wallet-core.jar  wallet-core.uuid  walletkey.properties
root@wallet-core-597c57d89c-z6hvz:/data# cat /data/walletkey.properties 
wallet.keys.data[0].coin=bnb
wallet.keys.data[0].seed=abcdedfefeds
wallet.keys.data[0].type=eth

wallet.keys.data[1].coin=arb
wallet.keys.data[1].seed=abcdedfefeds
wallet.keys.data[1].type=eth


wallet.keys.data[2].coin=op
wallet.keys.data[2].seed=abcdedfefeds
wallet.keys.data[2].type=eth


wallet.keys.data[3].coin=matic
wallet.keys.data[3].seed=abcdedfefeds
wallet.keys.data[3].type=eth

wallet.keys.data[4].coin=sol
wallet.keys.data[4].seed=abcdedfefeds
wallet.keys.data[4].type=sol

wallet.keys.data[5].coin=btc
wallet.keys.data[5].seed=abcdedfefeds
wallet.keys.data[5].type=btc

如果我们有多个文件需要这样挂载的话,我们可以操作如下

yaml 复制代码
          volumeMounts:
            - mountPath: /data/leaf.properties
              name: volume-zhma7
              subPath: leaf.properties
            - mountPath: /data/bootstrap.yml
              name: volume-zhma7
              subPath: bootstrap.yml
          workingDir: /data
      volumes:
        - configMap:
            defaultMode: 420
            items:
              - key: leaf.properties
                path: leaf.properties
              - key: bootstrap.yml
                path: bootstrap.yml
            name: leaf.properties
          name: volume-zhma7

kuboard挂载方式

然后启动的时候可以

handlebars 复制代码
java -Dspring.config.location=/data/leaf.properties -jar yourapp.jar
相关推荐
liux352818 分钟前
基于kubeadm部署Kubernetes 1.26.4 集群指南
云原生·容器·kubernetes
小章UPUP4 小时前
Kubernetes (K8s) 与 Podman 的比较
容器·kubernetes·podman
农民工老王7 小时前
K8s 1.31 私有化部署实战:从 Calico 崩溃到 NFS 挂载失败的排坑全记录
云原生·kubernetes
广州中轴线7 小时前
OpenStack on Kubernetes 生产部署实战(十四)
kubernetes·智能路由器·openstack
logocode_li9 小时前
OCI/CRI 双标准下:从 dockerd 到 containerd 的 K8s 运行时迭代史
docker·云原生·容器·k8s
人间打气筒(Ada)1 天前
k8s:CNI网络插件flannel与calico
linux·云原生·容器·kubernetes·云计算·k8s
江畔何人初1 天前
pod的内部结构
linux·运维·云原生·容器·kubernetes
苦逼IT运维1 天前
从 0 到 1 理解 Kubernetes:一次“破坏式”学习实践(一)
linux·学习·docker·容器·kubernetes
腾讯云开发者1 天前
言出法随 -- Chaterm如何通过ASR精准操作K8S
云原生·容器·kubernetes
伟大的大威1 天前
NVIDIA DGX Spark (ARM64/Blackwell) Kubernetes 集群 + GPU Operator 完整部署指南
大数据·spark·kubernetes