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 	# 关键代码 结束
相关推荐
L02082441 分钟前
Kubernetes Ingress|CNI 网络模型|Calico 网络策略|Pod 调度器完整实战教程
运维·网络·云原生·容器·kubernetes
吴声子夜歌2 小时前
Kubernetes权威指南——Kubernetes安装配置指南(网络配置)
网络·容器·kubernetes
闲云野鹤在人间3 小时前
Kubernetes Pod Scheduler 详解
云原生·容器·kubernetes
刘马想放假3 小时前
Copyparty 轻量文件共享:Docker Compose 部署、权限与多协议使用全指南
docker·容器
切糕师学AI5 小时前
Kubernetes 探针全解析:启动探针、存活探针与就绪探针(Startup/Liveness/Readiness Probe)
容器·kubernetes·探针·probe
xianyuCcCcCCCcc7 小时前
Kubernetes :健康检查、认证授权与可视化面板
运维·云原生·kubernetes·dashboard
fb_123458 小时前
K8s调度实战全景-Pod调度与资源管控
云原生·容器·kubernetes
吴声子夜歌9 小时前
Kubernetes权威指南——Kubernetes安装配置指南(二进制文件安装)
容器·kubernetes
江华森9 小时前
Kubernetes集群部署实战:使用kubeadm在4台ECS服务器上搭建K8s v1.31集群
云原生·容器·kubernetes