我试图遵循this link关于具有持久卷(完全相同)的Kubernetes MongoDB。
但是后来我部署了所有内容并查看了吊舱,发现了以下错误:
Name: mongodb-standalone-0
Namespace: default
Priority: 0
Node: <none>
Labels: app=database
controller-revision-hash=mongodb-standalone-7688499856
selector=mongodb-standalone
statefulset.kubernetes.io/pod-name=mongodb-standalone-0
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/mongodb-standalone
Containers:
mongodb-standalone:
Image: mongo:4.0.8
Port: <none>
Host Port: <none>
Environment:
MONGO_INITDB_ROOT_USERNAME_FILE: /etc/k8-training/admin/MONGO_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD_FILE: /etc/k8-training/admin/MONGO_ROOT_PASSWORD
Mounts:
/config from mongodb-conf (ro)
/data/db from mongodb-data (rw)
/docker-entrypoint-initdb.d from mongodb-scripts (ro)
/etc/k8-training from k8-training (ro)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-xbl5z (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
k8-training:
Type: Secret (a volume populated by a Secret)
SecretName: k8-training
Optional: false
mongodb-scripts:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mongodb-standalone
Optional: false
mongodb-conf:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mongodb-standalone
Optional: false
mongodb-data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mongodb-standalone
ReadOnly: false
default-token-xbl5z:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-xbl5z
Optional: false
QoS Class: BestEffort
Node-Selectors: kubernetes.io/hostname=mongodb-node
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling <unknown> default-scheduler 0/1 nodes are available: 1 node(s) didn't match node selector.
Warning FailedScheduling <unknown> default-scheduler 0/1 nodes are available: 1 node(s) didn't match node selector.
kubectl get nodes --show-labels
的结果:
minikube Ready master 43h v1.17.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=minikube,kubernetes.io/os=linux,node-role.kubernetes.io/master=
我试图找到一种方法来调试此问题,但一无所获。
我在Kubernetes中成功地使用我的应用程序运行了MongoDB,但问题是我想拥有持久的数据存储量,到目前为止,我找不到正确的方法来使其正常工作。 感谢您的帮助,谢谢。
我遵循了更改nodeSelector的方法,但是仍然遇到相同的错误:
Name: mongodb-standalone-0
Namespace: default
Priority: 0
Node: <none>
Labels: app=database
controller-revision-hash=mongodb-standalone-74895d955f
selector=mongodb-standalone
statefulset.kubernetes.io/pod-name=mongodb-standalone-0
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/mongodb-standalone
Containers:
mongodb-standalone:
Image: mongo:4.0.8
Port: <none>
Host Port: <none>
Environment:
MONGO_INITDB_ROOT_USERNAME_FILE: /etc/k8-training/admin/MONGO_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD_FILE: /etc/k8-training/admin/MONGO_ROOT_PASSWORD
Mounts:
/config from mongodb-conf (ro)
/data/db from mongodb-data (rw)
/docker-entrypoint-initdb.d from mongodb-scripts (ro)
/etc/k8-training from k8-training (ro)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-xbl5z (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
k8-training:
Type: Secret (a volume populated by a Secret)
SecretName: k8-training
Optional: false
mongodb-scripts:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mongodb-standalone
Optional: false
mongodb-conf:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mongodb-standalone
Optional: false
mongodb-data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mongodb-standalone
ReadOnly: false
default-token-xbl5z:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-xbl5z
Optional: false
QoS Class: BestEffort
Node-Selectors: kubernetes.io/hostname=minikube
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling <unknown> default-scheduler 0/1 nodes are available: 1 node(s) didn't find available persistent volumes to bind.
Warning FailedScheduling <unknown> default-scheduler 0/1 nodes are available: 1 node(s) didn't find available persistent volumes to bind.
答案 0 :(得分:2)
我猜您在节点上缺少标签kubernetes.io/hostname: mongodb-node
。
nodeSelector:
kubernetes.io/hostname: mongodb-node
kubectl label node <your_node_name> kubernetes.io/hostname=mongodb-node --overwrite
标记您的节点,但我不建议您使用这种方法。nodeSelector
更改为适当的名称,并用kubernetes.io/hostname
检查您的kubectl get no --show-labels
答案 1 :(得分:1)
将部署中的节点选择器更改为kubernetes.io/hostname=minikube
编辑:
在持久卷中,您需要修改并提供正确值的nodeAffinity
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube