k8s subpath

参考:https://www.cnblogs.com/gdut1425/p/13112176.html

一.使用场景一

一个pod中有多个容器挂载不同目录或者一个容器挂载不同目录,但只使用了一个volumes的情况

  1. 因为volumeMounts都使用了data-volume,当在/ttt下新建文件,/home2下也会出现相同文件,相当于都使用了/vvv/dd下的,没有数据隔离
  2. 解决方法:加上subPath,会在/vvv/dd下生成mn和nn两个文件夹,用来分别对应/ttt和/home2下的数据
apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  hostNetwork: true
  containers:
  - name: busybox
    image: busybox:1.34
    command: ["/bin/sh","-c","touch /ttt/a.txt;sleep 36000"]
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - mountPath: /ttt
      name: data-volume
      #subPath: mn     
    - mountPath: /home2
      name: data-volume
      #subPath: nn
  volumes:
  - name: data-volume
    hostPath:
      path: /vvv/dd
      type: DirectoryOrCreate
  restartPolicy: Always

二.使用场景二

不想覆盖pod中目录,只想改变某个文件,用configmap+subpath

创建configmap:kubectl create configmap nginxconf --from-file=/root/nginx.conf

piVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx 
  name: ssx-nginx-dm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template: 
    metadata:
      labels: 
        app: nginx
    spec: 
      containers: 
      - name: ssx-nginx-c
        image: nginx:1.17.1 
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80 
        volumeMounts: 
        - name: volume 
          #须写绝对路径,这样不会覆盖/etc/nginx目录,只会覆盖nginx.conf
          #如果写相对路径,且不加subpath会覆盖/etc/nginx目录
          mountPath: /etc/nginx/nginx.conf 
          subPath: nginx.conf #文件名称
      volumes:
      - name: volume 
        configMap:
          name: nginxconf
posted @ 2023-02-26 11:49  MISF  阅读(365)  评论(0编辑  收藏  举报
     JS过度和变形效果演示   
  
    html5.png