gpt4 book ai didi

mongodb - 使用 Mongo Operator 在 EKS/EFS 中部署 MongoDB

转载 作者:行者123 更新时间:2023-12-05 06:06:41 27 4
gpt4 key购买 nike

我正在尝试在 AWS EKS 上使用 kubernetes 运算符部署 mongodb,并为存储类提供 EFS。只需按照此处的文档示例:

https://github.com/mongodb/mongodb-kubernetes-operator

我不明白如何正确定义 PVC 命名。我查看了 Github 问题和 Stack Overflow。只是找不到示例来解决看似简单的问题。


apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: mongodb
spec:
members: 1
type: ReplicaSet
version: "4.2.6"
security:
authentication:
modes: ["SCRAM"]
users:
- name: my-user
db: admin
passwordSecretRef: # a reference to the secret that will be used to generate the user's password
name: my-user-password
roles:
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin
scramCredentialsSecretName: my-scram
statefulSet:
spec:
volumeClaimTemplates:
- metadata:
name: data-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: "efs-sc"

事件:

create Pod mongodb-0 in StatefulSet mongodb failed error: failed to create PVC -mongodb-0: PersistentVolumeClaim "-mongodb-0" is invalid: metadata.name: Invalid value: "-mongodb-0": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*') 

最佳答案

我复制了这个错误,并且在你的 yaml 文件中发现了一个错误。 voluemClaimTemplates 名称中缺少缩进。

这是您的 yaml 文件:

     volumeClaimTemplates:
- metadata:
👉 name: data-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: "efs-sc"

这是固定缩进的正确部分:

     volumeClaimTemplates:
- metadata:
👉 name: data-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: "efs-sc"

似乎由于这个错误,运算符(operator)无法正确获取名称,他正尝试使用默认模板创建卷。您可以使用 k get sts mongodb -oyaml 验证自己:

  volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeMode: Filesystem
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10G
volumeMode: Filesystem

关于mongodb - 使用 Mongo Operator 在 EKS/EFS 中部署 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65674473/

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