目录
- 1 什么是k8ssandra
- 2 安装k8ssandra
- 2.1 安装kubenetes
- 2.3 用helm安装k8ssandra
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上搭建kubernetes,在文章《virtualbox+ubuntu16搭建kubernetes集群的实现》已经有详细的介绍,这里不再赘述。为了更好的兼容性,我们指定了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/pkslow-samples
reference:
apache cassandra operations in kubernetes
k8ssandra get started
install k8ssandra on gke
k8ssandra helm chart
用helm部署kubernetes应用,支持多环境部署与版本回滚
附:
使用到的镜像:
root@k8ssandra:~# docker images | sort | grep -v repository | grep -v k8s.gcr.io alpine 3.12.2 b14afc6dfb98 9 months ago 5.57mb busybox 1.33.1 16ea53ea7c65 2 weeks ago 1.24mb busybox latest 16ea53ea7c65 2 weeks ago 1.24mb datastax/cass-config-builder 1.0.4 907e52ff2f78 4 months ago 354mb gcr.io/k8s-minikube/storage-provisioner v5 6e38f40d628d 6 months ago 31.5mb grafana/grafana 7.3.5 71716d95fc52 9 months ago 187mb jettech/kube-webhook-certgen v1.5.0 344297e197b6 11 months ago 44.7mb k8ssandra/cass-management-api 3.11.10-v0.1.27 e88cc3a8ce75 2 months ago 877mb k8ssandra/cass-management-api 4.0.0-v0.1.28 59b9869dd160 7 weeks ago 726mb k8ssandra/cass-operator v1.7.1 dd57363b0794 4 months ago 49.4mb k8ssandra/k8ssandra-tools latest 43e4bd91cf9b 42 hours ago 49mb k8ssandra/reaper-operator v0.3.3 b4cb9084a5e5 2 months ago 45.9mb k8ssandra/system-logger 9c4c3692 4dda0db106cb 4 months ago 5.66mb kiwigrid/k8s-sidecar 1.1.0 f4bb3bf1ddc7 11 months ago 82mb quay.io/prometheus-operator/prometheus-config-reloader v0.44.0 73bc771f8028 10 months ago 13.4mb quay.io/prometheus-operator/prometheus-operator v0.44.0 f5ab8d7a1a64 10 months ago 42.6mb quay.io/prometheus/prometheus v2.22.1 7cc97b58fb0e 10 months ago 168mb rancher/local-path-provisioner v0.0.20 933989e1174c 2 months ago 35mb stargateio/stargate-3_11 v1.0.29 c276fffd9964 3 months ago 537mb stargateio/stargate-4_0 v1.0.29 be4bae3748e1 3 months ago 546mb thelastpickle/cassandra-reaper 2.3.1 8ad2c2784ead 2 months ago 418mb
到此这篇关于k8ssandra入门教程之linux上部署k8ssandra到kubernetes的过程的文章就介绍到这了,更多相关k8ssandra部署kubernetes内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!