gpt4 book ai didi

postgresql - KubeDB on minikube 挂载本地目录

转载 作者:行者123 更新时间:2023-11-29 12:23:19 25 4
gpt4 key购买 nike

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

首先,这是我的 yaml 文件:

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
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
namespace: demo
name: adminpvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
release: development
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这反射(reflect)在下面的答案中,我已经从我所有的 yaml 文件中删除了 storageClass。

describe pod 看起来像这样:

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 容器并且它工作正常,也就是说我可以看到挂载其中的数据:

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 的唯一区别(据我所知,它背后有一个状态集)是我将 storageClass 保留在 PV 和 PVC 中!如果我删除存储类,我将在容器内看到挂载点,但它是空的并且没有数据

最佳答案

Remove the storageClass-line from the PersistentVolume

在 minikube 中尝试这样的事情:

这里是elasticsearch的例子

apiVersion: v1
kind: PersistentVolume
metadata:
name: elasticsearch
spec:
capacity:
storage: 400Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/elasticsearch/"

更多细节你也可以看看这个: pod has unbound PersistentVolumeClaims

编辑:

检查可用的存储类

kubectl get storageclass

对于PV量

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文件

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc
labels:
type: local
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
volumeName: postgres-pv

关于postgresql - KubeDB on minikube 挂载本地目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57947463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com