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 	# 关键代码 结束
相关推荐
JunLan~5 小时前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
小袁搬码9 小时前
Windows中指定路径安装DockerDesktop
windows·docker·容器·docker desktop
qq_312920119 小时前
docker 部署 kvm 图形化管理工具 WebVirtMgr
运维·docker·容器
踏雪Vernon9 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
条纹布鲁斯10 小时前
dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
docker·kubernetes
CP-DD12 小时前
Docker 容器化开发 应用
运维·docker·容器
老司机张师傅13 小时前
【微服务实战之Docker容器】第七章-Dockerfile解析
容器·dockerfile·虚悬镜像·docker学习
登云时刻14 小时前
Kubernetes集群外连接redis集群和使用redis-shake工具迁移数据(一)
redis·kubernetes·bootstrap
运维&陈同学14 小时前
【zookeeper03】消息队列与微服务之zookeeper集群部署
linux·微服务·zookeeper·云原生·消息队列·云计算·java-zookeeper
吴半杯15 小时前
gateway漏洞(CVE-2022-22947)
docker·kubernetes·gateway