Kubernetes Minikube与本地永久存储
我目前正在尝试在Minikube上部署以下内容。 我使用配置文件将一个主机路径用作minikube节点上的永久性存储。
apiVersion: v1
kind: PersistentVolume
metadata:
  name: "pv-volume"
spec:
  capacity:
    storage: "20Gi"
  accessModes:
    - "ReadWriteOnce"
  hostPath:
    path: /data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: "orientdb-pv-claim"
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "20Gi"
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: orientdbservice 
spec:
  #replicas: 1
  template:
    metadata:
     name: orientdbservice
     labels:
       run: orientdbservice
       test: orientdbservice
    spec:
      containers:
        - name: orientdbservice
          image: orientdb:latest
          env:
           - name: ORIENTDB_ROOT_PASSWORD
             value: "rootpwd"
          ports:
          - containerPort: 2480
            name: orientdb
          volumeMounts:
          - name: orientdb-config
            mountPath: /data/orientdb/config
          - name: orientdb-databases
            mountPath: /data/orientdb/databases 
          - name: orientdb-backup
            mountPath: /data/orientdb/backup
      volumes:
          - name: orientdb-config
            persistentVolumeClaim:
              claimName: orientdb-pv-claim
          - name: orientdb-databases
            persistentVolumeClaim:
              claimName: orientdb-pv-claim
          - name: orientdb-backup
            persistentVolumeClaim:
              claimName: orientdb-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  name: orientdbservice
  labels:
    run: orientdbservice
spec:
  type: NodePort
  selector:
    run: orientdbservice
  ports:
   - protocol: TCP
     port: 2480
     name: http
结果如下
#kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM                       STORAGECLASS   REASON    AGE
pv-volume                                  20Gi       RWO           Retain          Available                                                        4h
pvc-cd14d593-78fc-11e7-a46d-1277ec3dd2b5   20Gi       RWO           Delete          Bound       default/orientdb-pv-claim   standard                 4h
#kubectl get pvc
NAME                STATUS    VOLUME                                     CAPACITY   ACCESSMODES   STORAGECLASS   AGE
orientdb-pv-claim   Bound     pvc-cd14d593-78fc-11e7-a46d-1277ec3dd2b5   20Gi       RWO 
#kubectl get svc
NAME              CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
orientdbservice   10.0.0.16    <nodes>       2480:30552/TCP   4h
#kubectl get pods
NAME                              READY     STATUS              RESTARTS   AGE
orientdbservice-458328598-zsmw5   0/1       ContainerCreating   0          4h
#kubectl describe pod orientdbservice-458328598-zsmw5
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath   TypeReason      Message
  --------- --------    -----   ----            -------------   --------    ------      -------
  4h        1m      37  kubelet, minikube           Warning     FailedMount Unable to mount volumes for pod "orientdbservice-458328598-zsmw5_default(392b1298-78ff-11e7-a46d-1277ec3dd2b5)": timeout expired waiting for volumes to attach/mount for pod "default"/"orientdbservice-458328598-zsmw5". list of unattached/unmounted volumes=[orientdb-databases]
  4h        1m      37  kubelet, minikube           Warning     FailedSync  Error syncing pod
我看到以下错误
Unable to mount volumes for pod,timeout expired waiting for volumes to attach/mount for pod
在我的节点上创建Persistent Volume和PersistentVolumeClaim的方式中有不正确的地方。
minikube version: v0.20.0
感谢所有的帮助
你的配置没问题。
  在minikube v0.24.0 , minikube v0.25.0和minikube v0.26.1下测试没有任何问题。 
请记住, minikube正在积极开发中 ,特别是如果你在windows下,就像他们说的实验性软件一样 。
更新到更新版本的minikube并重新部署它。 这应该可以解决问题。
  您可以使用minikube update-check命令minikube update-check ,结果如下所示: 
$ minikube update-check
CurrentVersion: v0.25.0
LatestVersion: v0.26.1
  要升级minikube,只需输入minikube delete ,删除当前的minikube安装并按照说明下载新版本。 
$ minikube delete
There is a newer version of minikube available (v0.26.1).  Download it here:
https://github.com/kubernetes/minikube/releases/tag/v0.26.1
To disable this notification, run the following:
minikube config set WantUpdateNotification false
Deleting local Kubernetes cluster...
Machine deleted.
  对于provisioner: k8s.io/minikube-hostpath ,提供者provisioner: k8s.io/minikube-hostpath中的minikube不起作用。 
所以:
kubectl delete storageclass standard存储类kubectl delete storageclass standard 
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: docker.io/hostpath
reclaimPolicy: Retain
/data目录中创建三个子目录( backup , config和databases ): 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: orientdbservice
spec:
  #replicas: 1
  template:
    metadata:
     name: orientdbservice
     labels:
       run: orientdbservice
       test: orientdbservice
    spec:
      containers:
        - name: orientdbservice
          image: orientdb:latest
          env:
           - name: ORIENTDB_ROOT_PASSWORD
             value: "rootpwd"
          ports:
          - containerPort: 2480
            name: orientdb
          volumeMounts:
          - name: orientdb
            mountPath: /data/orientdb/config
            subPath: config
          - name: orientdb
            mountPath: /data/orientdb/databases
            subPath: databases
          - name: orientdb
            mountPath: /data/orientdb/backup
            subPath: backup
      volumes:
          - name: orientdb
            persistentVolumeClaim:
              claimName: orientdb-pv-claim 
kubectl create -f yourorientdb.yaml 
                        链接地址: http://www.djcxy.com/p/40135.html
                        
                        
                    