• Pod配置PersistentVolumeClaim详解


    1,创建PersistentVolume

    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: task-pv-volume
      labels:
        type: local
    spec:
      storageClassName: manual
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: "/mnt/data"

    执行上面配置文件后PersistentVolume被创建,通过命令查看

    kubectl get pv

    2,创建PersistentVolumeClaim

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: task-pv-claim
    spec:
      storageClassName: manual
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 3Gi

    PersistentVolumeClaim已邦定到PersistentVolume,创建后通过命令查看

    kubectl get pvc

     3,创建Pod使用PersistentVolumeClaim

    kind: Pod
    apiVersion: v1
    metadata:
      name: task-pv-pod
    spec:
      volumes:
        - name: task-pv-storage
          persistentVolumeClaim:
           claimName: task-pv-claim
      containers:
        - name: task-pv-container
          image: nginx
          ports:
            - containerPort: 80
              name: "http-server"
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: task-pv-storage

    容器目录/usr/share/nginx/html已挂载到宿主机/mnt/data

    参考资料

    https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/

    https://kubernetes.io/docs/concepts/storage/persistent-volumes/

    https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/

  • 相关阅读:
    第09组 Alpha冲刺 (6/6)
    第09组 Alpha冲刺 (5/6)
    第09组 Alpha冲刺 (4/6)
    第09组 Alpha冲刺 (3/6)
    第09组 Alpha冲刺 (2/6)
    第09组 Alpha冲刺 (1/6)
    第9组(71) 需求分析报告
    第9组(71) 团队展示
    结对编程作业
    第08组 Alpha冲刺 总结
  • 原文地址:https://www.cnblogs.com/birdstudio/p/9317882.html
Copyright © 2020-2023  润新知