From 38a6db28d3c20ee3cd7f6ba9ed9f60c54dddeb5b Mon Sep 17 00:00:00 2001 From: Muhammad Raisul Islam Evan Date: Wed, 25 Sep 2024 20:15:26 +0600 Subject: [PATCH] Fix Deletion Policy Halt Signed-off-by: Muhammad Raisul Islam Evan --- docs/guides/memcached/cli/cli.md | 5 +- docs/guides/memcached/concepts/memcached.md | 18 ++--- .../guides/memcached/quickstart/quickstart.md | 67 ++++++++++--------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/docs/guides/memcached/cli/cli.md b/docs/guides/memcached/cli/cli.md index 05c607ed37..41b442502f 100644 --- a/docs/guides/memcached/cli/cli.md +++ b/docs/guides/memcached/cli/cli.md @@ -86,7 +86,7 @@ spec: cpu: 250m memory: 64Mi replicas: 1 - deletionPolicy: Halt + deletionPolicy: WipeOut version: 1.6.22 status: observedGeneration: 1$7916315637361465932 @@ -115,7 +115,6 @@ Flag `--output=wide` is used to print additional information. List command supports short names for each object types. You can use it like `kubectl get `. Below are the short name for KubeDB objects: - Memcached: `mc` -- DormantDatabase: `drmn` You can print labels with objects. The following command will list all Memcached with their corresponding labels. @@ -249,8 +248,6 @@ If Deployment exists for a Memcached server, following fields can't be modified - spec.podTemplate.spec.nodeSelector - spec.podTemplate.spec.env -For DormantDatabase, `spec.origin` can't be edited using `kubectl edit` - ### How to Delete Objects `kubectl delete` command will delete an object in `default` namespace by default unless namespace is provided. The following command will delete a Memcached `memcached-dev` in default namespace diff --git a/docs/guides/memcached/concepts/memcached.md b/docs/guides/memcached/concepts/memcached.md index d5250a78dd..8c9348874c 100644 --- a/docs/guides/memcached/concepts/memcached.md +++ b/docs/guides/memcached/concepts/memcached.md @@ -78,7 +78,7 @@ spec: ports: - name: http port: 9200 - deletionPolicy: Halt + deletionPolicy: Delete ``` ### spec.replicas @@ -241,7 +241,6 @@ See [here](https://github.com/kmodules/offshoot-api/blob/kubernetes-1.16.3/api/v `deletionPolicy` gives flexibility whether to `nullify`(reject) the delete operation of `Memcached` crd or which resources KubeDB should keep or delete when you delete `Memcached` crd. KubeDB provides following four termination policies: - DoNotTerminate -- Halt - Delete (`Default`) - WipeOut @@ -249,18 +248,15 @@ When `deletionPolicy` is `DoNotTerminate`, KubeDB takes advantage of `Validation Following table show what KubeDB does when you delete Memcached crd for different termination policies, -| Behavior | DoNotTerminate | Halt | Delete | WipeOut | -| ----------------------------------- | :------------: | :------: | :------: | :------: | -| 1. Block Delete operation | ✓ | ✗ | ✗ | ✗ | -| 2. Delete PetSet | ✗ | ✓ | ✓ | ✓ | -| 3. Delete Services | ✗ | ✓ | ✓ | ✓ | -| 4. Delete Secrets | ✗ | ✗ | ✗ | ✓ | +| Behavior | DoNotTerminate | Delete | WipeOut | +| ---------------------------| :------------: | :------: | :------: | +| 1. Block Delete operation | ✓ | ✗ | ✗ | +| 2. Delete PetSet | ✗ | ✓ | ✓ | +| 3. Delete Services | ✗ | ✓ | ✓ | +| 4. Delete Secrets | ✗ | ✗ | ✓ | If you don't specify `spec.deletionPolicy` KubeDB uses `Delete` termination policy by default. -### spec.halted -Indicates that the database is halted and all offshoot Kubernetes resources except PVCs are deleted. - ## spec.helathChecker It defines the attributes for the health checker. - spec.healthChecker.periodSeconds specifies how often to perform the health check. diff --git a/docs/guides/memcached/quickstart/quickstart.md b/docs/guides/memcached/quickstart/quickstart.md index c2fea42b1d..fdb19ba2fe 100644 --- a/docs/guides/memcached/quickstart/quickstart.md +++ b/docs/guides/memcached/quickstart/quickstart.md @@ -322,6 +322,7 @@ status: phase: Ready ``` +## Connect with Memcached database Now, you can connect to this database using `telnet`. Here, we will connect to Memcached server from local-machine through port-forwarding. @@ -365,63 +366,69 @@ END quit ``` -## DoNotTerminate Property +## Database DeletionPolicy -When `deletionPolicy` is `DoNotTerminate`, KubeDB takes advantage of `ValidationWebhook` feature in Kubernetes 1.9.0 or later clusters to implement `DoNotTerminate` feature. If admission webhook is enabled, It prevents users from deleting the database as long as the `spec.deletionPolicy` is set to `DoNotTerminate`. You can see this below: +This field is used to regulate the deletion process of the related resources when `Memcached` object is deleted. User can set the value of this field according to their needs. The available options and their use case scenario is described below: + +**DoNotTerminate:** + +When `deletionPolicy` is set to `DoNotTerminate`, KubeDB takes advantage of `ValidationWebhook` feature in Kubernetes 1.9.0 or later clusters to implement `DoNotTerminate` feature. If admission webhook is enabled, It prevents users from deleting the database as long as the `spec.deletionPolicy` is set to `DoNotTerminate`. You can see this below: ```bash $ kubectl delete mc memcd-quickstart -n demo Error from server (Forbidden): admission webhook "memcachedwebhook.validators.kubedb.com" denied the request: memcached demo/memcd-quickstart is can't terminated. To delete, change spec.deletionPolicy ``` +Learn details of all `DeletionPolicy` [here](/docs/guides/memcached/concepts/memcached.md#specdeletionpolicy). -Now, run `kubectl edit mc memcd-quickstart -n demo` to set `spec.deletionPolicy` to `Halt`. Then you will be able to delete/halt the database. - -Learn details of all `DeletionPolicy` [here](/docs/guides/memcached/concepts/memcached.md#specdeletionpolicy) +**Delete:** -## Halt Database +If you want to delete the existing database but want to keep `secrets` then you might want to set the `Memcached` object `deletionPolicy` to `Delete`. In this setting, `PetSet` and `Services` will be deleted. -When [DeletionPolicy](/docs/guides/memcached/concepts/memcached.md#specdeletionpolicy) is set to `Halt` and you delete the memcached object, the KubeDB operator will delete the PetSet and its pods but leaves the PVCs, secrets and database backup (snapshots) intact. Learn details of all `DeletionPolicy` [here](/docs/guides/memcached/concepts/memcached.md#specdeletionpolicy). +When the [DeletionPolicy](/docs/guides/mysql/concepts/database/index.md#specdeletionpolicy) is set to `Delete` and the MySQL object is deleted, the KubeDB operator will delete the PetSet and its pods but leaves the `secret` intact. -You can also keep the memcached object and halt the database to resume it again later. If you halt the database, the KubeDB operator will delete the petsets and services but will keep the memcached object, pvcs, secrets and backup (snapshots). - -To halt the database, first you have to set the deletionPolicy to `Halt` in existing database. You can use the below command to set the deletionPolicy to `Halt`, if it is not already set. +Suppose, we have a database with `deletionPolicy` set to `Delete`. Now, are going to delete the database using the following command: ```bash -$ kubectl patch -n demo mc/memcd-quickstart -p '{"spec":{"deletionPolicy":"Halt"}}' --type="merge" -memcached.kubedb.com/memcd-quickstart patched +$ kubectl delete -n demo mc/memcd-quickstart +memcached.kubedb.com "memcd-quickstart" deleted ``` -Then, you have to set the `spec.halted` as true to set the database in a `Halted` state. You can use the below command. +Now, run the following command to get all memcached resources in `demo` namespaces, ```bash -$ kubectl patch -n demo mc/memcd-quickstart -p '{"spec":{"halted":true}}' --type="merge" -memcached.kubedb.com/memcd-quickstart patched +$ kubectl get sts,svc,secret,pvc -n demo +NAME TYPE DATA AGE +auth-secret Opaque 1 3h +mc-configuration Opaque 1 3h ``` -After that, kubedb will delete the petsets and services, and you can see the database Phase as `Halted`. You can see the bellow command. +From the above output, you can see that all memcached resources(`PetSet`, `Service` etc.) are deleted except `Secret`. -```bash -$ kubectl get memcached -n demo -NAME VERSION STATUS AGE -memcd-quickstart 1.6.22 Halted 91s -``` +>If you don't set the `deletionPolicy` then the kubeDB set the DeletionPolicy to `Delete` by-default. -## Resume Halted Memcached -Now, to resume the database, i.e. to get the same database setup back again, you have to set the `spec.halted` as false. You can use the below command. +**WipeOut:** -```bash -$ kubectl patch -n demo mc/memcd-quickstart -p '{"spec":{"halted":false}}' --type="merge" -memcached.kubedb.com/memcd-quickstart patched +You can totally delete the `Memcached` database and relevant resources without any tracking by setting `deletionPolicy` to `WipeOut`. KubeDB operator will delete all relevant resources of this `Memcached` database (i.e, `PetSet`, `Secrets`, `Services`) when the `deletionPolicy` is set to `WipeOut`. + +Suppose, we have a database with `deletionPolicy` set to `WipeOut`. Now, are going to delete the database using the following command: + +```yaml +$ kubectl delete -n demo mc/memcd-quickstart +memcached.kubedb.com "memcd-quickstart" deleted ``` -When the database is resumed successfully, you can see the database Status is set to `Ready`. +Now, run the following command to get all memcached resources in `demo` namespaces, ```bash -$ kc get memcached -n demo -NAME VERSION STATUS AGE -memcd-quickstart 1.6.22 Ready 30m +$ kubectl get sts,svc,secret -n demo +No resources found in demo namespace. ``` +From the above output, you can see that all memcached resources are deleted. there is no option to recreate/reinitialize your database if `deletionPolicy` is set to `Delete`. + +>Be careful when you set the `deletionPolicy` to `Delete`. Because there is no option to trace the database resources if once deleted the database. + + ## Cleaning up To cleanup the Kubernetes resources created by this tutorial, run: