Install KubeBlocks
The quickest way to try out KubeBlocks is to create a new Kubernetes cluster and install KubeBlocks using the playground. However, production environments are more complex, with applications running in different namespaces and with resource or permission limitations. This document explains how to deploy KubeBlocks on an existing Kubernetes cluster.
KubeBlocks is Kubernetes-native, you can use Helm or kubectl with a YAML file to install it. You can also use kbcli, an intuitive CLI tool, to install KubeBlocks.
To try out KubeBlocks on your local host, you can use the Playground or create a local Kubernetes test cluster first and then follow the steps in this tutorial to install KubeBlocks.
- Note that you install and uninstall KubeBlocks with the same tool. For example, if you install KubeBlocks with Helm, to uninstall it, you have to use Helm too.
- Make sure you have kubectl, Helm, or kbcli installed.
- Make sure you have Snapshot Controller installed before installing KubeBlocks. If you haven't installed it, follow the steps in section Install Snapshot Controller to install it.
Environment preparation
Resource Requirements | ||
---|---|---|
Control Plane | It is recommended to create 1 node with 4 cores, 4GB memory and 50GB storage. | |
Data Plane | MySQL | It is recommended to create at least 3 nodes with 2 cores, 4GB memory and 50GB storage. |
PostgreSQL | It is recommended to create at least 2 nodes with 2 cores, 4GB memory and 50GB storage. | |
Redis | It is recommended to create at least 2 nodes with 2 cores, 4GB memory and 50GB storage. | |
MongoDB | It is recommended to create at least 3 nodes with 2 cores, 4GB memory and 50GB storage. |
Install Snapshot Controller
The SnapshotController is a Kubernetes component that manages CSI Volume Snapshots, enabling users to create, restore, and delete snapshots of Persistent Volumes (PVs). KubeBlocks DataProtection Controller uses the Snapshot Controller to create and manage snapshots for databases.
If your Kubernetes cluster does NOT have the following CRDs, you likely also do not have a snapshot controller deployed and you need to install one.
kubectl get crd volumesnapshotclasses.snapshot.storage.k8s.io
kubectl get crd volumesnapshots.snapshot.storage.k8s.io
kubectl get crd volumesnapshotcontents.snapshot.storage.k8s.io
If you are sure you don't need the snapshot backup feature, you can install only the SnapshotController CRD and skip steps 1 and 2.
# v8.2.0 is the latest version of the external-snapshotter, you can replace it with the version you need.
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
Step 1. Deploy Snapshot Controller
You can install the Snapshot Controller using Helm or kubectl. Here are the steps to install the Snapshot Controller using Helm.
helm repo add piraeus-charts https://piraeus.io/helm-charts/
helm repo update
# Update the namespace to an appropriate value for your environment (e.g. kb-system)
helm install snapshot-controller piraeus-charts/snapshot-controller -n kb-system --create-namespace
For more information, please refer to Snapshot Controller Configuration.
Step 2. Verify Snapshot Controller installation
Check if the snapshot-controller Pod is running:
kubectl get pods -n kb-system | grep snapshot-controller
Output
snapshot-controller-xxxx-yyyy 1/1 Running 0 30s
If the pod is in a CrashLoopBackOff state, check logs:
kubectl logs -n kb-system deployment/snapshot-controller
Installation KubeBlocks
- Install with Helm
- Install with kubectl
- Install with kbcli
Follow these steps to install KubeBlocks using Helm.
-
Get the KubeBlocks version:
-
Option A - Get the latest stable version (e.g., v0.9.2):
curl -s "https://api.github.com/repos/apecloud/kubeblocks/releases?per_page=100&page=1" | jq -r '.[] | select(.prerelease == false) | .tag_name' | sort -V -r | head -n 1
-
Option B - View all available versions (including alpha and beta releases):
- Visit the KubeBlocks Releases.
- Or use the command:
curl -s "https://api.github.com/repos/apecloud/kubeblocks/releases?per_page=100&page=1" | jq -r '.[].tag_name' | sort -V -r
-
-
Create the required CRDs using your selected version:
# Replace <VERSION> with your selected version
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/<VERSION>/kubeblocks_crds.yaml
# Example: If the version is v0.9.2
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/v0.9.2/kubeblocks_crds.yaml -
Add the KubeBlocks Helm repo:
helm repo add kubeblocks https://apecloud.github.io/helm-charts
helm repo update -
Install KubeBlocks:
helm install kubeblocks kubeblocks/kubeblocks --namespace kb-system --create-namespace
If you want to install KubeBlocks with custom tolerations, you can use the following command:
helm install kubeblocks kubeblocks/kubeblocks --namespace kb-system --create-namespace \
--set-json 'tolerations=[ { "key": "control-plane-taint", "operator": "Equal", "effect": "NoSchedule", "value": "true" } ]' \
--set-json 'dataPlane.tolerations=[{ "key": "data-plane-taint", "operator": "Equal", "effect": "NoSchedule", "value": "true" }]'If you want to install KubeBlocks with a specified version, follow the steps below:
-
View the available versions in the KubeBlocks Releases.
-
Specify a version with
--version
and run the command below:helm install kubeblocks kubeblocks/kubeblocks --namespace kb-system --create-namespace --version=<VERSION>
noteBy default, the latest release version is installed.
-
Like any other resource in Kubernetes, KubeBlocks can be installed through a YAML manifest applied via kubectl
.
-
Get the KubeBlocks version:
-
Option A - Get the latest stable version (e.g., v0.9.2):
curl -s "https://api.github.com/repos/apecloud/kubeblocks/releases?per_page=100&page=1" | jq -r '.[] | select(.prerelease == false) | .tag_name' | sort -V -r | head -n 1
-
Option B - View all available versions (including alpha and beta releases):
- Visit the KubeBlocks Releases.
- Or use the command:
curl -s "https://api.github.com/repos/apecloud/kubeblocks/releases?per_page=100&page=1" | jq -r '.[].tag_name' | sort -V -r
-
-
Create the required CRDs using your selected version:
# Replace <VERSION> with your selected version
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/<VERSION>/kubeblocks_crds.yaml
# Example: If the version is v0.9.2
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/v0.9.2/kubeblocks_crds.yaml -
Install KubeBlocks:
# Replace <VERSION> with the same version used in step 2
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/<VERSION>/kubeblocks.yaml
# Example: If the version is v0.9.2
kubectl create -f https://github.com/apecloud/kubeblocks/releases/download/v0.9.2/kubeblocks.yamlnoteMake sure to use the same version for both CRDs and KubeBlocks installation to avoid compatibility issues.
The command kbcli kubeblocks install
installs KubeBlocks in the kb-system
namespace, or you can use the --namespace
flag to specify one.
kbcli kubeblocks install
If you want to install KubeBlocks with a specified version, follow the steps below.
-
View the available versions:
kbcli kubeblocks list-versions
To include alpha and beta releases, use:
kbcli kb list-versions --devel --limit=100
Or you can view all available versions in KubeBlocks Releases.
-
Specify a version with
--version
and run the command below:kbcli kubeblocks install --version=<VERSION>
By default, when installing KubeBlocks, kbcli installs the corresponding version of KubeBlocks. It's important to ensure the major versions of kbcli and KubeBlocks are the same, if you specify a different version explicitly here.
For example, you can install kbcli v0.9.2 with KubeBlocks v0.9.1, but using mismatched major versions, such as kbcli v0.9.2 with KubeBlocks v1.0.0, may lead to errors.
Verify KubeBlocks installation
Run the following command to check whether KubeBlocks is installed successfully.
- kubectl
- kbcli
kubectl -n kb-system get pods
Result
If the KubeBlocks Workloads are all ready, KubeBlocks has been installed successfully.
NAME READY STATUS RESTARTS AGE
kubeblocks-7cf7745685-ddlwk 1/1 Running 0 4m39s
kubeblocks-dataprotection-95fbc79cc-b544l 1/1 Running 0 4m39s
kbcli kubeblocks status
Result
If the KubeBlocks Workloads are all ready, KubeBlocks has been installed successfully.
KubeBlocks is deployed in namespace: kb-system, version: <VERSION>
>
KubeBlocks Workloads:
NAMESPACE KIND NAME READY PODS CPU(CORES) MEMORY(BYTES) CREATED-AT
kb-system Deployment kubeblocks 1/1 N/A N/A Oct 13,2023 14:26 UTC+0800
kb-system Deployment kubeblocks-dataprotection 1/1 N/A N/A Oct 13,2023 14:26 UTC+0800