k8s持久化

-
2024-07-08

 

案例一:不指定宿主机路径
apiVersion: v1
kind: Pod
metadata:
  name: hostpath
spec:
  nodeName: k8s1
  volumes:
  - name: data01
    emptyDir: {} 
  - name: data02
    # 指定类型为宿主机存储卷,该存储卷只要用于容器访问宿主机路径的需求。 
    hostPath:
      # 指定存储卷的宿主机路径
      path: /data
    containers:
  - name: web
    image: nginx:1.20.1-alpine
    volumeMounts:
    - name: data02
      mountPath: /usr/share/nginx/html

NFS

案例二:
 数据持久化之nfs实战案例
  apiVersion: v1
  kind: Pod
  metadata:
  name: volume-nfs
  spec:
  nodeName: k8s2
  volumes:
  - name: data
    # 指定存储卷类型是nfs
    nfs:
      # 指定nfs服务器的地址
      server: 10.0.0.231
      # 指定nfs对外暴露的挂载路径
      path: /volume-nfs
    containers:
  - name: web
    image: nginx:1.20.1-alpine
    volumeMounts:
    - name: data
      mountPath: /usr/share/nginx/html

苗世雷
地势坤君子厚德载物
公告

记录和学习
最新评论

加载中...