共计 3964 个字符,预计需要花费 10 分钟才能阅读完成。
1 什么是 K8ssandra
Cassandra 是一款十分优良的开源的分布式 NoSQL 数据库,被许多优良的大公司采纳,具备高可用、弹性扩大、性能好等特点。
正应 Cassandra 的劣势,咱们常常须要在云上服务应用,则须要部署 Cassandra 到 K8s 上,这就有了 K8ssandra。K8ssandra 不仅帮忙咱们能够疾速牢靠地在 Kubernetes 上部署 Cassandra,同时提供了许多组件,如监控、备份、同步、拜访等。而这些都是一个 Production-Ready 的产品不可或缺的。
K8ssandra 的组件架构图如下:
- Cass-operator:保障整个集群失常运行;
- Reaper:保障一致性的同步工具;
- Medusa:数据备份工具,反对 S3、GCP Cloud Storage 等;
- Stargate:对数据拜访提供 API;
- Prometheus+Grafana:云原生的罕用监控组件。
2 装置 K8ssandra
2.1 装置 Kubenetes
如何在 Ubuntu 上通过 Minikube 疾速启动一个 Kubernetes,在文章《服务网格 Istio 入门 - 具体记录 Kubernetes 装置 Istio 并应用》曾经有具体的介绍,这里不再赘述。为了更好的兼容性,咱们指定了 Kubernetes 的版本,命令如下:
minikube start --driver=none --kubernetes-version=v1.19.13
因为要用到 PVC,咱们创立一个 StorageClass:
$ kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
2.2 装置 helm3
咱们须要应用 Helm 来部署 K8ssandra,下载 Helm3 如下:
# 下载安装包
curl -LO https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz
# 解压
tar -zxvf helm-v3.7.0-linux-amd64.tar.gz
# 挪动到 bin 目录
mv linux-amd64/helm /usr/local/bin/helm
增加 Helm 的仓库:
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
查找一下 K8ssandra 相干的包:
$ 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...
咱们装置 k8ssandra/k8ssandra 就能够了。
2.3 用 Helm 装置 K8ssandra
Helm 是一个 Chart+Value 的治理形式,咱们筹备一个 yaml 文件(k8ssandra-values.yaml)来放一些变量:
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
装置 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
做一些必要的查看如下:
$ 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
检查一下 Pod 和 Service:
获取 K8ssandra 超级用户的用户名和明码
$ 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 减少节点
咱们为了高可用和容量,创立更多的 Cassandra Node,间接批改 k8ssandra-values.yaml 如下:
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
批改完之后,降级配置:
$ 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
查看 Kubernetes 的相干资源:
3 查看监控
咱们对外裸露 Grafana 服务来看看:
kubectl expose deployment k8ssandra-grafana --type=NodePort --name=grafana-out
找到对应的 NodePort 的端口 30348,拜访:http:// 外网 IP:30348
账号:admin/admin123
界面如下,提供良好的监控界面:
4 总结
K8ssandra 真是一个不错的开源我的项目,后续再介绍如何在开发中通过 K8ssandra 应用 Cassandra 吧。
代码请查看:https://github.com/LarryDpk/p…