K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程

目录

  • 1 什么是K8ssandra
  • 2 安装K8ssandra
    • 2.1 安装Kubenetes
    • 2.2 安装helm3
    • 2.3 用Helm安装K8ssandra
    • 2.4 增加节点
  • 3 查看监控
    • 4 总结

      1 什么是K8ssandra Cassandra是一款非常优秀的开源的分布式NoSQL数据库,被许多优秀的大公司采用,具有高可用、弹性扩展、性能好等特点。
      K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
      文章图片

      正应Cassandra的优势,我们经常需要在云上服务使用,则需要部署Cassandra到K8s上,这就有了K8ssandra。K8ssandra不仅帮助我们可以快速可靠地在Kubernetes上部署Cassandra,同时提供了许多组件,如监控、备份、同步、访问等。而这些都是一个Production-Ready的产品不可或缺的。
      K8ssandra的组件架构图如下:
      K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
      文章图片

      • 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 listNAMEURLk8ssandrahttps://helm.k8ssandra.io/stabletraefikhttps://helm.traefik.io/traefik

      查找一下K8ssandra相关的包:
      $ helm search repo k8ssandraNAMECHART VERSIONAPP VERSIONDESCRIPTIONk8ssandra/k8ssandra1.3.1Provisions and configures an instance of the en...k8ssandra/k8ssandra-common0.28.4Helper library containing functions used by man...k8ssandra/k8ssandra-operator0.31.01.0.0Kubernetes operator which handles the provision...k8ssandra/backup0.26.0Creates a CassandraBackup custom resource insta...k8ssandra/cass-operator0.31.01.8.0Kubernetes operator which handles the provision...k8ssandra/medusa-operator0.30.10.1.0Installs and configures the Medusa Operator for...k8ssandra/reaper-operator0.32.10.1.0Configures and installs the Reaper Operator for...k8ssandra/restore0.27.1Creates 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-pathsize: 5GiallowMultipleNodesPerWorker: trueheap:size: 1GnewGenSize: 1Gresources:requests:cpu: 1000mmemory: 2Gilimits:cpu: 1000mmemory: 2Gidatacenters:- name: dc1size: 1racks:- name: default kube-prometheus-stack:grafana:adminUser: adminadminPassword: admin123 stargate:enabled: truereplicas: 1heapMB: 256cpuReqMillicores: 200cpuLimMillicores: 1000

      安装K8ssandra:
      $ helm install -f k8ssandra-values.yaml k8ssandra k8ssandra/k8ssandraNAME: k8ssandraLAST DEPLOYED: Thu Sep 30 21:20:49 2021NAMESPACE: defaultSTATUS: deployedREVISION: 1

      做一些必要的检查如下:
      $ helm listNAMENAMESPACEREVISIONUPDATEDSTATUSCHARTAPP VERSIONk8ssandradefault12021-09-30 21:20:49.409672869 +0800 CST deployedk8ssandra-1.3.1$ kubectl get cassandradatacentersNAMEAGEdc14m34s$ kubectl describe CassandraDataCenter dc1 | grep "Cassandra Operator Progress:"Cassandra Operator Progress:Ready

      检查一下Pod和Service:
      【K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程】K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
      文章图片

      获取K8ssandra超级用户的用户名和密码
      $ kubectl get secret k8ssandra-superuser -o jsonpath="{.data.username}" | base64 --decode ; echok8ssandra-superuser$ kubectl get secret k8ssandra-superuser -o jsonpath="{.data.password}" | base64 --decode ; echoTNE5xOk45C1aQsj29qxw


      2.4 增加节点
      我们为了高可用和容量,创建更多的Cassandra Node,直接修改k8ssandra-values.yaml如下:
      cassandra:version: "4.0.0"cassandraLibDirVolume:storageClass: local-pathsize: 5GiallowMultipleNodesPerWorker: trueheap:size: 1GnewGenSize: 1Gresources:requests:cpu: 1000mmemory: 2Gilimits:cpu: 1000mmemory: 2Gidatacenters:- name: dc1size: 3racks:- name: racks1- name: racks2- name: racks3kube-prometheus-stack:grafana:adminUser: adminadminPassword: admin123 stargate:enabled: truereplicas: 1heapMB: 256cpuReqMillicores: 200cpuLimMillicores: 1000

      修改完之后,升级配置:
      $ helm upgrade -f k8ssandra-values.yaml k8ssandra k8ssandra/k8ssandraRelease "k8ssandra" has been upgraded. Happy Helming!NAME: k8ssandraLAST DEPLOYED: Fri Oct1 00:40:08 2021NAMESPACE: defaultSTATUS: deployedREVISION: 2

      查看Kubernetes的相关资源:
      K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
      文章图片


      3 查看监控 我们对外暴露Grafana服务来看看:
      kubectl expose deployment k8ssandra-grafana --type=NodePort --name=grafana-out

      找到对应的NodePort的端口30348,访问:http://外网IP:30348
      账号:admin/admin123
      界面如下,提供良好的监控界面:
      K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程
      文章图片


      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.ioalpine3.12.2b14afc6dfb989 months ago5.57MBbusybox1.33.116ea53ea7c652 weeks ago1.24MBbusyboxlatest16ea53ea7c652 weeks ago1.24MBdatastax/cass-config-builder1.0.4907e52ff2f784 months ago354MBgcr.io/k8s-minikube/storage-provisionerv56e38f40d628d6 months ago31.5MBgrafana/grafana7.3.571716d95fc529 months ago187MBjettech/kube-webhook-certgenv1.5.0344297e197b611 months ago44.7MBk8ssandra/cass-management-api3.11.10-v0.1.27e88cc3a8ce752 months ago877MBk8ssandra/cass-management-api4.0.0-v0.1.2859b9869dd1607 weeks ago726MBk8ssandra/cass-operatorv1.7.1dd57363b07944 months ago49.4MBk8ssandra/k8ssandra-toolslatest43e4bd91cf9b42 hours ago49MBk8ssandra/reaper-operatorv0.3.3b4cb9084a5e52 months ago45.9MBk8ssandra/system-logger9c4c36924dda0db106cb4 months ago5.66MBkiwigrid/k8s-sidecar1.1.0f4bb3bf1ddc711 months ago82MBquay.io/prometheus-operator/prometheus-config-reloaderv0.44.073bc771f802810 months ago13.4MBquay.io/prometheus-operator/prometheus-operatorv0.44.0f5ab8d7a1a6410 months ago42.6MBquay.io/prometheus/prometheusv2.22.17cc97b58fb0e10 months ago168MBrancher/local-path-provisionerv0.0.20933989e1174c2 months ago35MBstargateio/stargate-3_11v1.0.29c276fffd99643 months ago537MBstargateio/stargate-4_0v1.0.29be4bae3748e13 months ago546MBthelastpickle/cassandra-reaper2.3.18ad2c2784ead2 months ago418MB

      到此这篇关于K8ssandra入门教程之Linux上部署K8ssandra到Kubernetes的过程的文章就介绍到这了,更多相关K8ssandra部署Kubernetes内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

        推荐阅读