Skip to content

Commit

Permalink
Add --purge flag (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored Mar 9, 2018
1 parent a3fd995 commit 62b20a8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 28 deletions.
16 changes: 12 additions & 4 deletions docs/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,26 @@ Please note that this will install KubeDB cli from master branch which might inc

## Install KubeDB Operator

To use `kubedb`, you will need to install KubeDB [operator](https://github.com/kubedb/operator).
To use `kubedb`, you will need to install KubeDB [operator](https://github.com/kubedb/operator). KubeDB operator can be installed via a script or as a Helm chart.

### Using YAML
### Using Script

KubeDB can be installed via installer script included in the [/hack/deploy](https://github.com/kubedb/cli/tree/0.8.0-beta.2/hack/deploy) folder.
To install KubeDB in your Kubernetes cluster, run the following command:

```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh | bash
```

After successful installation, you should have a `kubedb-operator-***` pod running in the `kube-system` namespace.

```console
$ kubectl get pods -n kube-system | grep kubedb-operator
kubedb-operator-65d97f8cf9-8c9tj 2/2 Running 0 1m
```

#### Customizing Installer

You can see the full list of flags available to installer using `-h` flag.
The installer script and associated yaml files can be found in the [/hack/deploy](https://github.com/kubedb/cli/tree/0.8.0-beta.2/hack/deploy) folder. You can see the full list of flags available to installer using `-h` flag.

```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh | bash -s -- -h
Expand All @@ -69,6 +76,7 @@ options:
--run-on-master run kubedb operator on master
--enable-admission-webhook configure admission webhook for kubedb CRDs
--uninstall uninstall kubedb
--purge purges kubedb crd objects and crds
```

If you would like to run KubeDB operator pod in `master` instances, pass the `--run-on-master` flag:
Expand Down
33 changes: 17 additions & 16 deletions docs/setup/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ section_menu_id: setup
# Uninstall KubeDB

Please follow the steps below to uninstall KubeDB:
To uninstall KubeDB operator, run the following command:

- Delete the deployment and service used for KubeDB operator.
```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh \
| bash -s -- --uninstall [--namespace=NAMESPACE]

```console
$ curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/kubedb.sh \
| bash -s -- --uninstall [--namespace=NAMESPACE]
+ kubectl delete deployment -l app=kubedb -n kube-system
deployment "kubedb-operator" deleted
+ kubectl delete service -l app=kubedb -n kube-system
service "kubedb-operator" deleted
+ kubectl delete serviceaccount -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrolebindings -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrole -l app=kubedb -n kube-system
No resources found
```

The above command will leave the KubeDB crd objects as-is. If you wish to **nuke** all KubeDB crd objects, also pass the `--purge` flag. This will keep a copy of KubeDB crd objects in your current directory.

+ kubectl delete deployment -l app=kubedb -n kube-system
deployment "kubedb-operator" deleted
+ kubectl delete service -l app=kubedb -n kube-system
service "kubedb-operator" deleted
+ kubectl delete serviceaccount -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrolebindings -l app=kubedb -n kube-system
No resources found
+ kubectl delete clusterrole -l app=kubedb -n kube-system
No resources found
```

- Now, wait several seconds for KubeDB to stop running. To confirm that KubeDB operator pod(s) have stopped running, run:

Expand Down
59 changes: 51 additions & 8 deletions hack/deploy/kubedb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -eou pipefail

crds=(elasticsearches memcacheds mongodbs mysqls postgreses redises snapshots dormantdatabases)

echo "checking kubeconfig context"
kubectl config current-context || { echo "Set a context (kubectl use-context <context>) out of the following:"; echo; kubectl config get-contexts; exit 1; }
echo ""
Expand Down Expand Up @@ -52,6 +54,7 @@ export KUBEDB_ENABLE_ADMISSION_WEBHOOK=false
export KUBEDB_DOCKER_REGISTRY=kubedb
export KUBEDB_IMAGE_PULL_SECRET=
export KUBEDB_UNINSTALL=0
export KUBEDB_PURGE=0

KUBE_APISERVER_VERSION=$(kubectl version -o=json | $ONESSL jsonpath '{.serverVersion.gitVersion}')
$ONESSL semver --check='>=1.9.0' $KUBE_APISERVER_VERSION
Expand All @@ -73,6 +76,7 @@ show_help() {
echo " --run-on-master run kubedb operator on master"
echo " --enable-admission-webhook configure admission webhook for kubedb CRDs"
echo " --uninstall uninstall kubedb"
echo " --purge purges kubedb crd objects and crds"
}

while test $# -gt 0; do
Expand Down Expand Up @@ -129,6 +133,10 @@ while test $# -gt 0; do
export KUBEDB_UNINSTALL=1
shift
;;
--purge)
export KUBEDB_PURGE=1
shift
;;
*)
show_help
exit 1
Expand All @@ -150,6 +158,45 @@ if [ "$KUBEDB_UNINSTALL" -eq 1 ]; then
kubectl delete rolebindings -l app=kubedb --namespace $KUBEDB_NAMESPACE
kubectl delete role -l app=kubedb --namespace $KUBEDB_NAMESPACE

echo "waiting for kubedb operator pod to stop running"
for (( ; ; )); do
pods=($(kubectl get pods --all-namespaces -l app=kubedb -o jsonpath='{range .items[*]}{.metadata.name} {end}'))
total=${#pods[*]}
if [ $total -eq 0 ] ; then
break
fi
sleep 2
done

# https://github.com/kubernetes/kubernetes/issues/60538
if [ "$KUBEDB_PURGE" -eq 1 ]; then
for crd in "${crds[@]}"; do
pairs=($(kubectl get ${crd}.kubedb.com --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name} {.metadata.namespace} {end}' || true))
total=${#pairs[*]}

# save objects
if [ $total -gt 0 ]; then
echo "dumping ${crd} objects into ${crd}.yaml"
kubectl get ${crd}.kubedb.com --all-namespaces -o yaml > ${crd}.yaml
fi

for (( i=0; i<$total; i+=2 )); do
name=${pairs[$i]}
namespace=${pairs[$i + 1]}
# remove finalizers
kubectl patch ${crd}.kubedb.com $name -n $namespace -p '{"metadata":{"finalizers":[]}}' --type=merge
# delete crd object
echo "deleting ${crd} $namespace/$name"
kubectl delete ${crd}.kubedb.com $name -n $namespace
done

# delete crd
kubectl delete crd ${crd}.kubedb.com || true
done
fi

echo
echo "Successfully uninstalled KubeDB!"
exit 0
fi

Expand Down Expand Up @@ -189,21 +236,17 @@ if [ "$KUBEDB_ENABLE_ADMISSION_WEBHOOK" = true ]; then
curl -fsSL https://raw.githubusercontent.com/kubedb/cli/0.8.0-beta.2/hack/deploy/admission.yaml | $ONESSL envsubst | kubectl apply -f -
fi

echo
echo "waiting until kubedb operator deployment is ready"
$ONESSL wait-until-ready deployment kubedb-operator --namespace $KUBEDB_NAMESPACE || { echo "KubeDB operator deployment failed to be ready"; exit 1; }

echo "waiting until kubedb apiservice is available"
$ONESSL wait-until-ready apiservice v1alpha1.admission.kubedb.com || { echo "KubeDB apiservice failed to be ready"; exit 1; }

echo "waiting until kubedb crds are ready"
$ONESSL wait-until-ready crd elasticsearches.kubedb.com || { echo "Elasticsearch CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd memcacheds.kubedb.com || { echo "Memcached CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd mongodbs.kubedb.com || { echo "MongoDB CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd mysqls.kubedb.com || { echo "MySQL CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd postgreses.kubedb.com || { echo "Postgres CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd redises.kubedb.com || { echo "Redis CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd snapshots.kubedb.com || { echo "Snapshot CRD failed to be ready"; exit 1; }
$ONESSL wait-until-ready crd dormantdatabases.kubedb.com || { echo "DormantDatabase CRD failed to be ready"; exit 1; }
for crd in "${crds[@]}"; do
$ONESSL wait-until-ready crd ${crd}.kubedb.com || { echo "$crd crd failed to be ready"; exit 1; }
done

echo
echo "Successfully installed KubeDB operator!"

0 comments on commit 62b20a8

Please sign in to comment.