Apache Cassandra 是一个可大规模扩展的开源 NoSQL 数据库。Cassandra 非常适合管理跨多个数据中心和云的大量结构化、半结构化和非结构化数据。
Access-server 则是通过akka框架实现了去中心化的集群,也同样适合使用Kubernetes进行集群部署。
利用 Kubernetes 提供的服务能力,比如 PersistentVolume 和 StatefulSet,我们可以提供一种具有容灾能力的 Cassandra和Access-server 安装,并确保它的数据(状态)是安全的。
1、创建pv
[root@localhost cassandra]# cat local-volumes.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: cassandra-storage-1
labels:
type: local
app: cassandra
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/data/cassandra-storage-1
persistentVolumeReclaimPolicy: Recycle
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: cassandra-storage-2
labels:
type: local
app: cassandra
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/data/cassandra-storage-2
persistentVolumeReclaimPolicy: Recycle
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: cassandra-storage-3
labels:
type: local
app: cassandra
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/data/cassandra-data-3
persistentVolumeReclaimPolicy: Recycle
2、创建svc
[root@localhost test]# cat cassandra-service.yaml
apiVersion: v1
kind: Service
metadata:
name: cassandra
labels:
app: cassandra
spec:
clusterIP: None
ports:
- port: 9042
selector:
app: cassandra
3、创建cassandra StatefulSet
[root@localhost test]# cat cassandta-statefulset.yaml
---
apiVersion: "apps/v1beta1"
kind: StatefulSet
metadata:
name: cassandra
spec:
serviceName: cassandra
replicas: 3
template:
metadata:
labels:
app: cassandra
spec:
containers:
- name: cassandra
image: cassandra:3.11
imagePullPolicy: IfNotPresent
resources:
requests:
memory: "1Gi"
cpu: "0.5"
limits:
memory: "1Gi"
cpu: "0.5"
securityContext:
capabilities:
add:
- IPC_LOCK
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- nodetool drain
ports:
- containerPort: 7000
name: intra-node
- containerPort: 7001
name: tls-intra-node
- containerPort: 7199
name: jmx
- containerPort: 9042
name: cql
env:
- name: CASSANDRA_SEEDS
value: "cassandra-0.cassandra.default.svc.cluster.local,cassandra-1.cassandra.default.svc.cluster.local,cassandra-2.cassandra.default.svc.cluster.local"
- name: MAX_HEAP_SIZE
value: 512M
- name: HEAP_NEWSIZE
value: 100M
- name: CASSANDRA_CLUSTER_NAME
value: "cx"
- name: CASSANDRA_DC
value: "DC1"
- name: CASSANDRA_RACK
value: "Rack1"
- name: CASSANDRA_ENDPOINT_SNITCH
value: GossipingPropertyFileSnitch
volumeMounts:
- name: cassandra-storage
mountPath: /var/lib/cassandra
volumeClaimTemplates:
- metadata:
name: cassandra-storage
annotations: # comment line if you want to use a StorageClass
# or specify which StorageClass
volume.beta.kubernetes.io/storage-class: "" # comment line if you
# want to use a StorageClass or specify which StorageClass
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi