I have deployed a sharded cluster of Mongodb in my kubernetes cluster as you can see in the yml configuration file below and is working just fine. I followed this doc/article for the setup. Now the issue is that I have to increase the size of my Mongodb storage but I am getting some error. Any help is highly appreciated. Thanks.
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
In the above yaml Kubedb Mongodb deployment file I changed the storage from 1 Gi to 2 Gi and tried to reapply it again: kubectl apply -f kubedb-mongodb-deployment.yaml
but i am getting this error:
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
The error you experience here is because you try to rescale by editing the mongodb-deployment.yaml
which is kind: MongoDB
and not the PVC itself. As stated in the official documentation:
Note: spec.storage section is used to create PVC for database pod. It will create PVC with storage size specified instorage.resources.requests field. Don’t specify limits here. PVC does not get resized automatically.
What you should do is to edit the PVC .yaml
file with the desired values. Check out this blog to find out how to do that in more detail.
Please let me know if that helped.