1 what is k8sandra
Cassandra is an excellent open source distributed NoSQL database, which is adopted by many excellent large companies. It has the characteristics of high availability, elastic expansion and good performance.
Due to the advantages of Cassandra, we often need to use services on the cloud, so we need to deploy Cassandra to K8s, which has k8sandra. K8sandra not only helps us to deploy Cassandra on Kubernetes quickly and reliably, but also provides many components, such as monitoring, backup, synchronization, access, etc. These are indispensable to a production ready product.
The component architecture diagram of K8ssandra is as follows:
- Cass operator: ensure the normal operation of the whole cluster;
- Reaper: a synchronization tool to ensure consistency;
- Medusa: data backup tool, supporting S3, GCP Cloud Storage, etc;
- Stargate: provides API for data access;
- Prometheus+Grafana: common monitoring component of cloud native.
2 install K8ssandra
2.1 installation of Kubenetes
How to quickly start a Kubernetes through Minikube on Ubuntu, in the article< Getting started with Istio in service grid - detailed record of Kubernetes installing Istio and using >It has been introduced in detail and will not be repeated here. For better compatibility, we specify the version of Kubernetes. The command is as follows:
minikube start --driver=none --kubernetes-version=v1.19.13
Because PVC is used, we create a StorageClass:
$ kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
2.2 installation helm3
We need to use Helm to deploy K8ssandra. Download Helm3 as follows:
# Download installation package curl -LO https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz # decompression tar -zxvf helm-v3.7.0-linux-amd64.tar.gz # Move to bin directory mv linux-amd64/helm /usr/local/bin/helm
Add Helm's warehouse:
helm repo add k8ssandra https://helm.k8ssandra.io/stable $ helm repo list NAME URL k8ssandra https://helm.k8ssandra.io/stable traefik https://helm.traefik.io/traefik
Find k8sandra related packages:
$ helm search repo k8ssandra NAME CHART VERSION APP VERSION DESCRIPTION k8ssandra/k8ssandra 1.3.1 Provisions and configures an instance of the en... k8ssandra/k8ssandra-common 0.28.4 Helper library containing functions used by man... k8ssandra/k8ssandra-operator 0.31.0 1.0.0 Kubernetes operator which handles the provision... k8ssandra/backup 0.26.0 Creates a CassandraBackup custom resource insta... k8ssandra/cass-operator 0.31.0 1.8.0 Kubernetes operator which handles the provision... k8ssandra/medusa-operator 0.30.1 0.1.0 Installs and configures the Medusa Operator for... k8ssandra/reaper-operator 0.32.1 0.1.0 Configures and installs the Reaper Operator for... k8ssandra/restore 0.27.1 Creates a CassandraRestore custom resource inst...
We can install k8sandra / k8sandra.
2.3 install K8ssandra with Helm
Helm is a Chart+Value management method. We prepare a yaml file (k8sandra values. Yaml) to put some variables:
cassandra: version: "4.0.0" cassandraLibDirVolume: storageClass: local-path size: 5Gi allowMultipleNodesPerWorker: true heap: size: 1G newGenSize: 1G resources: requests: cpu: 1000m memory: 2Gi limits: cpu: 1000m memory: 2Gi datacenters: - name: dc1 size: 1 racks: - name: default kube-prometheus-stack: grafana: adminUser: admin adminPassword: admin123 stargate: enabled: true replicas: 1 heapMB: 256 cpuReqMillicores: 200 cpuLimMillicores: 1000
Install K8ssandra:
$ helm install -f k8ssandra-values.yaml k8ssandra k8ssandra/k8ssandra NAME: k8ssandra LAST DEPLOYED: Thu Sep 30 21:20:49 2021 NAMESPACE: default STATUS: deployed REVISION: 1
Make some necessary checks as follows:
$ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION k8ssandra default 1 2021-09-30 21:20:49.409672869 +0800 CST deployed k8ssandra-1.3.1 $ kubectl get cassandradatacenters NAME AGE dc1 4m34s $ kubectl describe CassandraDataCenter dc1 | grep "Cassandra Operator Progress:" Cassandra Operator Progress: Ready
Check the Pod and Service:
Get the user name and password of k8sandra super user
$ kubectl get secret k8ssandra-superuser -o jsonpath="{.data.username}" | base64 --decode ; echo k8ssandra-superuser $ kubectl get secret k8ssandra-superuser -o jsonpath="{.data.password}" | base64 --decode ; echo TNE5xOk45C1aQsj29qxw
2.4 adding nodes
For high availability and capacity, we create more Cassandra nodes and directly modify k8sandra-values.yaml as follows:
cassandra: version: "4.0.0" cassandraLibDirVolume: storageClass: local-path size: 5Gi allowMultipleNodesPerWorker: true heap: size: 1G newGenSize: 1G resources: requests: cpu: 1000m memory: 2Gi limits: cpu: 1000m memory: 2Gi datacenters: - name: dc1 size: 3 racks: - name: racks1 - name: racks2 - name: racks3 kube-prometheus-stack: grafana: adminUser: admin adminPassword: admin123 stargate: enabled: true replicas: 1 heapMB: 256 cpuReqMillicores: 200 cpuLimMillicores: 1000
After modification, upgrade the configuration:
$ helm upgrade -f k8ssandra-values.yaml k8ssandra k8ssandra/k8ssandra Release "k8ssandra" has been upgraded. Happy Helming! NAME: k8ssandra LAST DEPLOYED: Fri Oct 1 00:40:08 2021 NAMESPACE: default STATUS: deployed REVISION: 2
Check out Kubernetes resources:
3 view monitoring
Let's expose the Grafana service to see:
kubectl expose deployment k8ssandra-grafana --type=NodePort --name=grafana-out
Find the port 30348 of the corresponding NodePort. Access: http: / / Internet IP:30348
Account No.: admin/admin123
The interface is as follows, providing a good monitoring interface:
4 Summary
K8sandra is really a good open source project. Later, let's introduce how to use Cassandra through k8sandra in development.
Please check the code: https://github.com/LarryDpk/pkslow-samples