kubernetes中的常用存储类型

这里介绍hostPath

利用hostPath的挂载卷

假如容器希望使用主机目录下的/opt/etcd/ssl/下的认证文件,可以像如下这样定义:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    env:
    - name: ETCD_KEY_FILE
      value: "/opt/etcd/ssl/server-key.pem"
    volumeMounts:
    - mountPath: /opt/etcd/ssl/  #容器中文件所在位置
      name: etcd-ssl             #卷名称,要和volumes中的一致
  volumes:
  - name: etcd-ssl
    hostPath:
      # directory location on host
      path: /opt/etcd/ssl        #主机文件所在的位置
      # this field is optional
      type: Directory
      readOnly: true
原文地址:https://www.cnblogs.com/janeysj/p/13850792.html