0

正如您在下面的 yml 配置文件中看到的那样,我已经在我的 kubernetes 集群中部署了一个 Mongodb 分片集群,并且工作正常。我按照这个文档/文章进行了设置。现在的问题是我必须增加我的 Mongodb 存储的大小,但我遇到了一些错误。非常感谢任何帮助。谢谢。

apiVersion: kubedb.com/v1alpha1
kind: MongoDB
metadata:
  name: mongo-sh
  namespace: mongo
spec:
  version: 4.1.7
  shardTopology:
    configServer:
      replicas: 3
      storage:
        resources:
          requests:
            storage: 1Gi #I tried to change this to 2Gi
        storageClassName: fast
    mongos:
      replicas: 2
      strategy:
        type: RollingUpdate
    shard:
      replicas: 3
      shards: 3
      storage:
        resources:
          requests:
            storage: 1Gi #I tried to change this to 2Gi
        storageClassName: fast
  monitor:
    agent: prometheus.io/builtin

在上面的 yaml Kubedb Mongodb 部署文件中,我将存储从 1 Gi 更改为 2 Gi 并尝试再次重新应用它:kubectl apply -f kubedb-mongodb-deployment.yaml

但我收到此错误:

Error from server (BadRequest): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"kubedb.com/v1alpha1\",\"kind\":\"MongoDB\",\"metadata\":{\"annotations\":{},\"name\":\"mongo-sh\",\"namespace\":\"mongo\"},\"spec\":{\"monitor\":{\"agent\":\"prometheus.io/builtin\"},\"shardTopology\":{\"configServer\":{\"replicas\":3,\"storage\":{\"resources\":{\"requests\":{\"storage\":\"2Gi\"}},\"storageClassName\":\"fast\"}},\"mongos\":{\"replicas\":2,\"strategy\":{\"type\":\"RollingUpdate\"}},\"shard\":{\"replicas\":3,\"shards\":3,\"storage\":{\"resources\":{\"requests\":{\"storage\":\"2Gi\"}},\"storageClassName\":\"fast\"}}},\"version\":\"4.1.7\"}}\n"}},"spec":{"shardTopology":{"configServer":{"storage":{"resources":{"requests":{"storage":"2Gi"}}}},"shard":{"storage":{"resources":{"requests":{"storage":"2Gi"}}}}}}}
to:
Resource: "kubedb.com/v1alpha1, Resource=mongodbs", GroupVersionKind: "kubedb.com/v1alpha1, Kind=MongoDB"
Name: "mongo-sh", Namespace: "mongo"
Object: &{map["apiVersion":"kubedb.com/v1alpha1" "kind":"MongoDB" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"kubedb.com/v1alpha1\",\"kind\":\"MongoDB\",\"metadata\":{\"annotations\":{},\"name\":\"mongo-sh\",\"namespace\":\"mongo\"},\"spec\":{\"monitor\":{\"agent\":\"prometheus.io/builtin\"},\"shardTopology\":{\"configServer\":{\"replicas\":3,\"storage\":{\"resources\":{\"requests\":{\"storage\":\"1Gi\"}},\"storageClassName\":\"fast\"}},\"mongos\":{\"replicas\":2,\"strategy\":{\"type\":\"RollingUpdate\"}},\"shard\":{\"replicas\":3,\"shards\":3,\"storage\":{\"resources\":{\"requests\":{\"storage\":\"1Gi\"}},\"storageClassName\":\"fast\"}}},\"version\":\"4.1.7\"}}\n"] "creationTimestamp":"2020-01-31T09:14:24Z" "finalizers":["kubedb.com"] "generation":'\x05' "name":"mongo-sh" "namespace":"mongo" "resourceVersion":"200611174" "selfLink":"/apis/kubedb.com/v1alpha1/namespaces/mongo/mongodbs/mongo-sh" "uid":"12f07f14-440a-11ea-92d9-42010a9c0fd3"] "spec":map["certificateSecret":map["secretName":"mongo-sh-keyfile"] "databaseSecret":map["secretName":"mongo-sh-auth"] "monitor":map["agent":"prometheus.io/builtin" "prometheus":map["port":'\ufffd'] "resources":map[]] "serviceTemplate":map["metadata":map[] "spec":map[]] "shardTopology":map["configServer":map["podTemplate":map["controller":map[] "metadata":map[] "spec":map["livenessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x05'] "readinessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x01'] "resources":map[] "securityContext":map["fsGroup":'\u03e7' "runAsNonRoot":%!q(bool=true) "runAsUser":'\u03e7']]] "replicas":'\x03' "storage":map["dataSource":<nil> "resources":map["requests":map["storage":"1Gi"]] "storageClassName":"fast"]] "mongos":map["podTemplate":map["controller":map[] "metadata":map[] "spec":map["livenessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x05'] "readinessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x01'] "resources":map[] "securityContext":map["fsGroup":'\u03e7' "runAsNonRoot":%!q(bool=true) "runAsUser":'\u03e7']]] "replicas":'\x02' "strategy":map["type":"RollingUpdate"]] "shard":map["podTemplate":map["controller":map[] "metadata":map[] "spec":map["livenessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x05'] "readinessProbe":map["exec":map["command":["mongo" "--eval" "db.adminCommand('ping')"]] "failureThreshold":'\x03' "periodSeconds":'\n' "successThreshold":'\x01' "timeoutSeconds":'\x01'] "resources":map[] "securityContext":map["fsGroup":'\u03e7' "runAsNonRoot":%!q(bool=true) "runAsUser":'\u03e7']]] "replicas":'\x03' "shards":'\x03' "storage":map["dataSource":<nil> "resources":map["requests":map["storage":"1Gi"]] "storageClassName":"fast"]]] "storageType":"Durable" "terminationPolicy":"Pause" "updateStrategy":map["type":"RollingUpdate"] "version":"4.1.7"] "status":map["observedGeneration":"4$6211945921239001045" "phase":"Running"]]}
for: "mongodb.yaml": admission webhook "mongodb.validators.kubedb.com" denied the request: precondition failed for: map[metadata:map[annotations:map[kubectl.kubernetes.io/last-applied-configuration:{"apiVersion":"kubedb.com/v1alpha1","kind":"MongoDB","metadata":{"annotations":{},"name":"mongo-sh","namespace":"mongo"},"spec":{"monitor":{"agent":"prometheus.io/builtin"},"shardTopology":{"configServer":{"replicas":3,"storage":{"resources":{"requests":{"storage":"2Gi"}},"storageClassName":"fast"}},"mongos":{"replicas":2,"strategy":{"type":"RollingUpdate"}},"shard":{"replicas":3,"shards":3,"storage":{"resources":{"requests":{"storage":"2Gi"}},"storageClassName":"fast"}}},"version":"4.1.7"}}
] generation:6] spec:map[shardTopology:map[configServer:map[storage:map[resources:map[requests:map[storage:2Gi]]]] shard:map[storage:map[resources:map[requests:map[storage:2Gi]]]]]]].At least one of the following was changed:
    apiVersion
    kind
    name
    namespace
    spec.storageType
    spec.storage
    spec.databaseSecret
    spec.certificateSecret
    spec.init
    spec.replicaSet.name
    spec.shardTopology.*.storage
    spec.shardTopology.*.prefix
4

1 回答 1

0

您在这里遇到的错误是因为您尝试通过编辑而不是 PVC 本身来重新mongodb-deployment.yaml缩放kind: MongoDB。如官方文档中所述:

注意:spec.storage 部分用于为数据库 pod 创建 PVC。它将创建具有指定 instorage.resources.requests 字段的存储大小的 PVC。不要在此处指定限制。PVC 不会自动调整大小。

您应该做的是.yaml使用所需的值编辑 PVC 文件。查看此博客以了解如何更详细地执行此操作。

请让我知道这是否有帮助。

于 2020-02-07T14:01:27.253 回答