K8S volumn 挂载文件

bash 复制代码
volumeMounts:
- name: cfg-vol
  mountPath: /etc/grafana/provisioning/datasources
- name: cfg-ini
  mountPath: /usr/share/grafana/conf/sample.ini
  subPath: sample.ini
- name: cfg-temp
  mountPath: /usr/share/grafana/conf/test.json
  subPath: test.json
bash 复制代码
  volumes:
  - name: cfg-vol
    configMap:
      name: cm-grafana-yaml
  - name: cfg-ini
    configMap:
      name: cm-grafana-ini
  - name: cfg-temp
    configMap:
      name: cm-grafana-temp
需求

将一个configmap 内的两个文件挂载在一个pod的不同目录下

  • /app/conf/grafanaoracle.properties
  • /app/start-timeshift.sh

创建一个configmap

bash 复制代码
kind: ConfigMap
apiVersion: v1
metadata:
  labels:
    app.kubernetes.io/managed-by: Helm
  name: test-config
data:
  grafanaoracle.properties: |
    name=kevin
    nage=19
  start-timeshift.sh: |
    #!/bin/sh
    cd /app/influxdb-timeshift-proxy
    INFLUXDB=nms-influxdb:8086 /usr/bin/npm run start

创建一个deploy

bash 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    zcm-app: test-configmap
  name: test-configmap
spec:
  replicas: 1
  selector:
    matchLabels:
      zcm-app: test-configmap
  template:
    metadata:
      labels:
        zcm-app: test-configmap
    spec:
      containers:
      - env:
        - name: CLOUD_APP_NAME
          value: paas_test-configmap
        image: nginx
        imagePullPolicy: IfNotPresent
        name: test-configmap
        ports:
        - containerPort: 9999
          name: http-oracle
          protocol: TCP
        volumeMounts:       # 关键代码 开始
        - mountPath: /app/start-timeshift.sh
          name: properties
          readOnly: true
          subPath: start-timeshift.sh
        - mountPath: /app/conf/grafanaoracle.properties
          name: properties
          readOnly: true
          subPath: grafanaoracle.properties
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - configMap:
          defaultMode: 420
          items:
          - key: grafanaoracle.properties  # key 和 path 同名即可
            path: grafanaoracle.properties
          - key: start-timeshift.sh
            path: start-timeshift.sh
          name: test-configmap
        name: properties 	# 关键代码 结束
相关推荐
wdfk_prog6 分钟前
ros教程02:创建 catkin Workspace、Package 与第一个 ROS1 C++ Node
运维·缓存·docker·容器·ros
阿里云云原生2 小时前
剧透丨AI 原生研发组织的探索和实践
云原生
名字还没想好☜4 小时前
Docker 网络实战:bridge/host/none/自定义网络、容器互通与端口映射踩坑
运维·docker·kubernetes
探索云原生6 小时前
KubeClipper 1.7.0 发布:Operation 优化与 Kubernetes 1.37 支持
linux·docker·云原生·kubernetes·go
fengkai45457 小时前
八、Docker详解1-3
运维·docker·容器
MrSYJ10 小时前
Veth pair 细讲
docker·云原生·容器
Elastic 中国社区官方博客10 小时前
将 Vercel 数据导入 Elastic:无需安装任何东西的无服务器可观测性
大数据·运维·elasticsearch·搜索引擎·云原生·serverless·全文检索
秦jh_11 小时前
【Docker】容器
运维·docker·容器
天天喝旺仔13 小时前
Prometheus + Grafana 监控告警体系搭建实战:从 Exporter 指标采集、PromQL 查询到 Alertmanager 告警落地
容器·kubernetes·grafana·prometheus·时序数据库
大盛供应链·卢生1 天前
哪些国产芯片可以替代进口芯片,哪些替代不了
fpga开发·容器