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 	# 关键代码 结束
相关推荐
weixin_443290695 分钟前
【Docker】安装及使用
docker·容器·eureka
nvd1143 分钟前
K8S - 用service account 登陆kubectl
kubernetes
二进制杯莫停44 分钟前
k8s pod网络故障注入,命令行实现
网络·容器·kubernetes
it技术分享just_free1 小时前
基于 K8S kubernetes 的常见日志收集方案
linux·运维·docker·云原生·容器·kubernetes·k8s
小叶子来了啊1 小时前
002.k8s(Kubernetes)一小时快速入门(先看docker30分钟)
java·容器·kubernetes
it技术分享just_free2 小时前
基于 K8S kubernetes 搭建 安装 EFK日志收集平台
运维·docker·云原生·容器·kubernetes·k8s
lizhou8283 小时前
win10下使用docker、k8s部署java应用
java·docker·kubernetes
wydydgh4 小时前
docker 升级步骤
运维·docker·容器
2401_840192274 小时前
在k8s中,客户端访问服务的链路流程,ingress--->service--->deployment--->pod--->container
云原生·容器·kubernetes