Kubernetes Minikube具有本地持久存储空间

时间:2017-08-04 16:12:26

标签: 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

感谢所有帮助

2 个答案:

答案 0 :(得分:5)

您的配置正常。

minikube v0.24.0minikube v0.25.0minikube v0.26.1下测试没有任何问题。

请记住 minikube正在积极开发,特别是如果您在Windows下,就像他们说实验软件

更新到较新版本的minikube并重新部署。这应该可以解决问题。

您可以使用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.

答案 1 :(得分:2)

对于somereasonprovisioner: k8s.io/minikube-hostpath中的配置工具minikube无法正常工作。

所以:

  • 删除默认存储类kubectl delete storageclass standard
  • 创建以下存储类:
    
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: standard
    provisioner: docker.io/hostpath
    reclaimPolicy: Retain
    
  • 同样在您的卷安装中,您有一个PVC绑定到一个PV,因此,不是多个卷只有一个卷并使用不同的子路径安装它们,这将创建三个子目录(backup,{{1} }&amp; config)在主持人的databases目录中:

/data
  - 现在部署你的yaml: 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

相关问题