1.emptyDir挂载
emptyDir类型会在pod创建时,在node节点随机分配一个目录,无需指定路径。当pod更新或者被删除是,挂载的文件夹也会随之删除,属于本地临时存储
下面例子,容器内的/var/lib/influxdb的数据 会挂载到宿主机随机分配的临时目录
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:{}
generation: 1
labels:
app: influxdb-app
name: influxdb-app
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: influxdb-app
template:
metadata:
creationTimestamp: null
labels:
app: influxdb-app
name: influxdb-app
spec:
containers:
- env:
- name: INFLUXDB_ADMIN_USER
value: admin
- name: INFLUXDB_ADMIN_PASSWORD
value: 123456
image: smart33690/influxdb:1.8.3
imagePullPolicy: IfNotPresent
name: influxdb
resources: {}
volumeMounts:
- mountPath: /var/lib/influxdb
name: influxdb-storage
dnsPolicy: ClusterFirst
hostNetwork: true
hostPID: true
nodeSelector:
node-role.kubernetes.io/edge: ""
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- emptyDir: {}
name: influxdb-storage
2.hostPath挂载
hostPath类型会在pod创建时,按指定的目录在node上创建文件夹,当pod更新或者被删除是,文件夹的数据不会被删除删除,属于本地持久存储
下面例子,容器内的/var/lib/influxdb的数据 会挂载到宿主机的/var/lib/influxdb目录
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:{}
generation: 1
labels:
app: influxdb-app
name: influxdb-app
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: influxdb-app
template:
metadata:
creationTimestamp: null
labels:
app: influxdb-app
name: influxdb-app
spec:
containers:
- env:
- name: INFLUXDB_ADMIN_USER
value: admin
- name: INFLUXDB_ADMIN_PASSWORD
value: 123456
image: smart33690/influxdb:1.8.3
imagePullPolicy: IfNotPresent
name: influxdb
resources: {}
volumeMounts:
- mountPath: /var/lib/influxdb
name: influxdb-storage
dnsPolicy: ClusterFirst
hostNetwork: true
hostPID: true
nodeSelector:
node-role.kubernetes.io/edge: ""
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- hostPath:
path: /var/lib/influxdb
name: influxdb-storage
支持开源,拥抱开源,为开发者赋能!