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 	# 关键代码 结束
相关推荐
chenglin01620 分钟前
架构设计——云原生与分布式系统架构
云原生·架构
007php0071 小时前
Go 语言常用命令使用与总结
java·linux·服务器·前端·数据库·docker·容器
你是我的日月星河2 小时前
Docker部署单节点使用KRaft存储数据的Kafka与可视化界面Kafka-Map
docker·容器·kafka
Cyber4K3 小时前
企业级-搭建CICD(持续集成持续交付)实验手册
ci/cd·云原生·容器
搞不懂语言的程序员3 小时前
docker 搭建zookper集群,快照虚拟机多机模拟
运维·docker·容器
Rysxt_4 小时前
Docker Swarm 与 Kubernetes (K8s) 全面对比教程
docker·容器·kubernetes
Britz_Kevin6 小时前
从零开始的云计算生活——第五十四天,悬梁刺股,kubernetes模块之组件与网络
网络·kubernetes·生活
Moss Huang12 小时前
docker-runc not installed on system
java·docker·容器
辉辉健身中18 小时前
docker和k8s的区别
docker·容器·kubernetes
Json_19 小时前
使用Docker部署ZLMediaKit流媒体服务器实现gb/t28181协议的设备
服务器·docker·容器