我正在尝试为我的 Pod 设置 PersistentVolumeClaims
。现在的问题是,当部署
成功时,Pod 处于pending
状态。当我尝试描述 Pod 时,我收到错误,为什么它们没有旋转起来,如下所示:
Warning FailedScheduling 20s (x3 over 22s) default-scheduler 0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 pod has unbound immediate PersistentVolumeClaims.
这是用于创建持久卷并在部署中引用它的 yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-pvc
namespace: mongo
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
namespace: mongo
labels:
name: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-password
volumeMounts:
- name: data
mountPath: /data/db
volumes:
- name: data
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-express
namespace: mongo
labels:
app: mongo-express
spec:
replicas: 1
selector:
matchLabels:
app: mongo-express
template:
metadata:
labels:
app: mongo-express
spec:
containers:
- name: mongo-express
image: mongo-express
ports:
- containerPort: 8081
env:
- name: ME_CONFIG_MONGODB_SERVER
valueFrom:
configMapKeyRef:
name: mongodb-url
key: database_url
- name: ME_CONFIG_MONGODB_ADMINUSERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-username
- name: ME_CONFIG_MONGODB_ADMINPASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-password
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: my-pvc
---
.
.
.
我已经从上面删除了其他 yaml 配置,并保留了必要的配置,以便于阅读。
当我尝试使用 kubectl get pvc -n mongo
查看 PVC 的状态时,我得到以下 pending
状态
my-pvc Pending 9m54s
有人可以告诉我哪里做错了吗?
最佳答案
如 answer to pod has unbound PersistentVolumeClaims 中所述,如果您使用PersistentVolumeClaim
,您通常需要一个卷配置程序来进行动态卷配置。较大的云提供商通常有此功能,Minikube 也有可以启用的功能。
除非您的集群中有卷配置程序,否则您需要创建 PersistentVolume资源,可能还有一个 StorageClass 并声明如何使用您的存储系统。
Configure a Pod to Use a PersistentVolume for Storage描述了如何创建带有 hostPath
的 PersistentVolume
,这可能有利于学习或开发,但通常不会在应用程序的生产中使用。
关于mongodb - 2 个 pod 具有未绑定(bind)的立即 PersistentVolumeClaims - Kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64341805/