KubeDB is a command to interact with databases running in Kubernetes. It supports dumping, restoring, and dropping into a database shell. Optional flags are available to set running database parameters (see each command's help entry for more details). If no flags are given, KubeDB will inspect the pod configuration and attempt to configure itself via the Kubernetes EnvVar API.
- PostgreSQL
- MariaDB/MySQL
- MongoDB
- Redis
- Meilisearch [beta]
Click to expand
brew install clevyr/tap/kubedb
Click to expand
KubeDB has a Docker image available at ghcr.io/clevyr/kubedb
docker pull ghcr.io/clevyr/kubedb
To use this image, you will need to volume bind a couple of directories into the Docker container:
- Kubeconfig: Typically, this will be at
~/.kube/config
, and the container expects it to be at/.kube/config
.- Example:
-v "$HOME/.kube/config:/.kube/config"
- Example:
- Data dir: A directory to hold the generated dump or that has a sql file to restore. The container expects this to be at
/data
.- Example:
-v "$PWD:/data"
- Example:
docker run --rm -it -v "$HOME/.kube:/.kube" -v "$PWD:/data" ghcr.io/clevyr/kubedb dump
Click to expand
-
If you don't have it already, install the
ca-certificates
packagesudo apt install ca-certificates
-
Add Clevyr's apt repository
echo 'deb [trusted=yes] https://apt.clevyr.com /' | sudo tee /etc/apt/sources.list.d/clevyr.list
-
Update apt repositories
sudo apt update
-
Install KubeDB
sudo apt install kubedb
Click to expand
-
If you don't have it already, install the
ca-certificates
packagesudo yum install ca-certificates
-
Add Clevyr's rpm repository to
/etc/yum.repos.d/clevyr.repo
[clevyr] name=Clevyr baseurl=https://rpm.clevyr.com enabled=1 gpgcheck=0
-
Install KubeDB
sudo yum install kubedb
Click to expand
Install kubedb-bin with your AUR helper of choice.
KubeDB requires an existing Kubeconfig. See below for details.
All of the KubeDB subcommands and flags are documented in the docs directory.
- Verify cluster/database connection
kubedb status
- Dump a database (filename will be generated)
kubedb dump
- Dump a database to a specific filename
kubedb dump example.sql.gz
- Restore a SQL file to a database
kubedb restore example.sql.gz
- Set up a local port-forward
kubedb port-forward
- Open an interactive prompt
kubedb exec
-
To connect to a Kubernetes cluster running in GKE, ensure you have the
gcloud
command installed. If you have it then skip to step 2.
Otherwise, you can either take a look at GCP's install doc, or run:brew install google-cloud-sdk gcloud init
-
Install the
gke-cloud-auth-plugin
per the GCP install doc or run:gcloud components install gke-gcloud-auth-plugin
-
Then to generate a Kubeconfig, run:
gcloud container clusters get-credentials --project=PROJECT CLUSTER_NAME
-
If you don’t encounter any errors then you should be connected and ready to work with databases! To verify, type in the following command and press the tab key twice:
kubedb exec -n <TAB><TAB>
All of your current namespaces should show up in your shell. Many of the KubeDB flags support tab completion.