首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >minikube挂载本地目录上的KubeDB

minikube挂载本地目录上的KubeDB
EN

Stack Overflow用户
提问于 2019-09-16 03:15:56
回答 3查看 933关注 0票数 3

我试图在minikube上使用kubedb运行postgres,当我从本地目录(位于我的Mac上)挂载我的数据时,当pod运行时,我没有得到预期的行为,发生了两件事:一是挂载显然不在那里,二是我看到了错误pod has unbound immediate PersistentVolumeClaims

首先,下面是我的yaml文件:

代码语言:javascript
复制
apiVersion: v1
kind: PersistentVolume
metadata:
  name: adminvol
  namespace: demo
  labels:
    release: development
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /Users/myusername/local_docker_poc/admin/lib/postgresql/data
代码语言:javascript
复制
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: demo
  name: adminpvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  selector:
    matchLabels:
      release: development
代码语言:javascript
复制
apiVersion: kubedb.com/v1alpha1
kind: Postgres
metadata:
  name: quick-postgres
  namespace: demo
spec:
  version: "10.2-v2"
  storageType: Durable
  storage:
    accessModes:
    - ReadWriteMany
    resources:
      requests:
        storage: 1Gi
  volumeMounts:
    - mountPath: /busy
      name: naim
      persistentVolumeClaim:
        claimName: adminpvc
  terminationPolicy: WipeOut

根据下面答案中反映的this,我已经从我所有的yaml文件中删除了storageClass。

describe pod如下所示:

代码语言:javascript
复制
Name:               quick-postgres-0
Namespace:          demo
Priority:           0
PriorityClassName:  <none>
Node:               minikube/10.0.2.15
Start Time:         Wed, 25 Sep 2019 22:18:44 +0300
Labels:             controller-revision-hash=quick-postgres-5d5bcc4698
                    kubedb.com/kind=Postgres
                    kubedb.com/name=quick-postgres
                    kubedb.com/role=primary
                    statefulset.kubernetes.io/pod-name=quick-postgres-0
Annotations:        <none>
Status:             Running
IP:                 172.17.0.7
Controlled By:      StatefulSet/quick-postgres
Containers:
  postgres:
    Container ID:  docker://6bd0946f8197ddf1faf7b52ad0da36810cceff4abb53447679649f1d0dba3c5c
    Image:         kubedb/postgres:10.2-v3
    Image ID:      docker-pullable://kubedb/postgres@sha256:9656942b2322a88d4117f5bfda26ee34d795cd631285d307b55f101c2f2cb8c8
    Port:          5432/TCP
    Host Port:     0/TCP
    Args:
      leader_election
      --enable-analytics=true
      --logtostderr=true
      --alsologtostderr=false
      --v=3
      --stderrthreshold=0
    State:          Running
      Started:      Wed, 25 Sep 2019 22:18:45 +0300
    Ready:          True
    Restart Count:  0
    Environment:
      APPSCODE_ANALYTICS_CLIENT_ID:  90b12fedfef2068a5f608219d5e7904a
      NAMESPACE:                     demo (v1:metadata.namespace)
      PRIMARY_HOST:                  quick-postgres
      POSTGRES_USER:                 <set to the key 'POSTGRES_USER' in secret 'quick-postgres-auth'>      Optional: false
      POSTGRES_PASSWORD:             <set to the key 'POSTGRES_PASSWORD' in secret 'quick-postgres-auth'>  Optional: false
      STANDBY:                       warm
      STREAMING:                     asynchronous
      LEASE_DURATION:                15
      RENEW_DEADLINE:                10
      RETRY_PERIOD:                  2
    Mounts:
      /dev/shm from shared-memory (rw)
      /var/pv from data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from quick-postgres-token-48rkd (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  data-quick-postgres-0
    ReadOnly:   false
  shared-memory:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:     Memory
    SizeLimit:  <unset>
  quick-postgres-token-48rkd:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  quick-postgres-token-48rkd
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  39s   default-scheduler  pod has unbound immediate PersistentVolumeClaims
  Normal   Scheduled         39s   default-scheduler  Successfully assigned demo/quick-postgres-0 to minikube
  Normal   Pulled            38s   kubelet, minikube  Container image "kubedb/postgres:10.2-v3" already present on machine
  Normal   Created           38s   kubelet, minikube  Created container
  Normal   Started           38s   kubelet, minikube  Started container

我按照官方手册关于如何挂载pvc here进行调试,我使用相同的pv和pvc挂载了一个简单的busybox容器,它工作得很好,也就是说,我可以看到里面有数据的挂载:

代码语言:javascript
复制
apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: demo
spec:
  containers:
    - name: busybox
      image: busybox
      command:
        - sleep
        - "3600"
      volumeMounts:
        - mountPath: /busy
          name: adminpvc
  volumes:
    - name: adminpvc
      persistentVolumeClaim:
        claimName: adminpvc

我自己的pod和KubeDB的唯一不同之处在于我把pod放在PV和PVC里(据我所知,后面有一个状态设置)。如果我删除存储类,我将看到容器内的挂载点,但它是空的并且没有数据

EN

回答 3

Stack Overflow用户

发布于 2019-09-16 14:09:51

代码语言:javascript
复制
Remove the storageClass-line from the PersistentVolume

在minikube中,尝试如下所示:

以下是elasticsearch的示例

代码语言:javascript
复制
apiVersion: v1
kind: PersistentVolume
metadata:
  name: elasticsearch
spec:
  capacity:
    storage: 400Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/elasticsearch/"

有关更多详细信息,您也可以查看以下内容:pod has unbound PersistentVolumeClaims

编辑

检查可用的storageclasses

代码语言:javascript
复制
kubectl get storageclass

对于PV卷

代码语言:javascript
复制
kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/postgres-pv

PVC文件

代码语言:javascript
复制
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pvc
  labels:
    type: local
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  volumeName: postgres-pv
票数 0
EN

Stack Overflow用户

发布于 2019-09-26 16:55:42

您正在使用kubedb.com/v1alpha1的自定义Postgres-resource。

它们定义了一种处理storage的自定义方法。似乎你必须设置 spec.storage.storageClassName-key,因为

“没有storageClassName的聚氯乙烯是不完全相同的,集群会根据DefaultStorageClass准入插件是否打开而采取不同的处理方式。”

现在选择哪个StorageClass

既然你在使用Minikube,我建议你坚持使用Minikube的minikube-hostpath。您可以查看它是否可用:

代码语言:javascript
复制
$ kubectl get storageclass
NAME                 PROVISIONER                AGE
standard (default)   k8s.io/minikube-hostpath   2m36s

支持dynamic provisioning,设置为默认StorageClass。

尝试设置spec.storage.storageClassName: minikube-hostpath并相应地更新您的卷。

票数 0
EN

Stack Overflow用户

发布于 2020-06-05 22:41:28

实际上不可能做到你想要做的事情。

Kubedb的所有兴趣都是为了轻松构建数据库集群,这意味着每个实例都有专用的卷。Kubedb的操作员按需创建卷(PVC),并将它们绑定到创建的pods。

您正在为动态CRD定义堆栈卷,因此它无法工作。

另外,操作员不会将volumeMounts传递给StatefulSet (由于上述原因)。

为了实现您的场景,您必须自己编写StatefulSet

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57947463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档