几种临时存储

emptyDir

apiVersion: v1
kind: Pod
metadata:
  name: "multi-container-pod"
  namespace: default
  labels:
    app: "multi-container-pod"
spec:
  volumes:    ### 以后见到的所有名字 都应该是一个合法的域名方式
  - name: nginx-vol
    emptyDir: {}  ### docker匿名挂载,外部创建一个位置  /abc
  containers:  ## kubectl exec -it podName  -c nginx-container(容器名)-- /bin/sh
  - name: nginx-container
    image: "nginx"
    volumeMounts:  #声明卷挂载  -v
      - name: nginx-vol
        mountPath: /usr/share/nginx/html
  - name: content-container
    image: "alpine"
    command: ["/bin/sh","-c","while true;do sleep 1; date > /app/index.html;done;"]
    volumeMounts: 
      - name: nginx-vol
        mountPath: /app

hostPath 场景同步时间

apiVersion: v1
kind: Pod
metadata:
  name: busy-box-test
  namespace: default
spec:
  containers:
  - name: busy-box-test
    image: busybox
    imagePullPolicy: IfNotPresent
    volumeMounts: ## 描述容器想把自己的哪个路径进行挂载
    - name: localtime
      mountPath: /etc/localtime  ## 挂到容器的这个位置
  volumes:  ## 描述每个volumeMounts到底该怎么挂载
    - name: localtime
      hostPath:  ## 主机的这个文件
        path: /usr/share/zoneinfo/Asia/Shanghai  ## 上海时区
apiVersion: v1
kind: Pod
metadata:
  name: "pod-time"
  namespace: default
  labels:
    app: "pod-time"
spec:
  containers:
  - name: pod-time
    image: "busybox"
    command: ["sleep","60000"]
    volumeMounts: ## 描述容器想把自己的哪个路径进行挂载
    - name: localtime
      mountPath: /etc/localtime  ## 挂到容器的这个位置
      # subPath: localtime  ## /etc/localtime
  volumes:  ## 描述每个volumeMounts到底该怎么挂载
    - name: localtime
      hostPath:  ## 主机的这个文件  
        path: /usr/share/zoneinfo/Asia/Shanghai
        type: Directory  ### 到底是什么。文件/文件夹 .....

posted @ 2022-05-31 10:45  z_先生  阅读(42)  评论(0编辑  收藏  举报