使用 Mongo 操作员在 EKS/EFS 中部署 MongoDB
deploy MongoDB in EKS/EFS with Mongo Operator
我正在尝试在 AWS EKS 上使用 kubernetes 运算符部署 mongodb,并使用 EFS 进行存储 class。只需按照此处的文档示例:
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"
似乎由于这个错误,操作员无法正确获取名称,他正尝试使用默认模板创建卷。您可以通过 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
我正在尝试在 AWS EKS 上使用 kubernetes 运算符部署 mongodb,并使用 EFS 进行存储 class。只需按照此处的文档示例:
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"
似乎由于这个错误,操作员无法正确获取名称,他正尝试使用默认模板创建卷。您可以通过 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