作者:李毓
redis是属于数据库,在ceph为后端存储的情况下,适合rbd模式。所以我们先搭建RBD模式的存储。
紧接上一节CEPH所讲,创建自动供给PV.
[root@adm-master src]# cd external-storage-master/ceph/rbd/deploy/
[root@adm-master deploy]# ls
non-rbac rbac README.md
[root@adm-master deploy]# pwd
/usr/local/src/external-storage-master/ceph/rbd/deploy
kubectl apply -f ./rbac
[root@adm-master rbac]# kubectl get pods
NAME READY STATUS RESTARTS AGE
rbd-provisioner-c968dcb4b-fws8q 1/1 Running 0 42m
创建secret
[root@adm-master test-rbd]# cat ceph-secret-rbd.yaml
apiVersion: v1
kind: Secret
metadata:
name: ceph-secret-rbd
namespace: test-redis
type: "ceph.com/rbd"
data:
key: QVFCem9UOWdiQWNwRXhBQXFET0VKTnFMWGJRZm1TTmhObkRRdUE9PQo=
在ceph节点创建pool池
ceph osd pool create k8stest 256
rbd create rbda -s 1024 -p k8stest
rbd feature disable k8stest/rbda object-map fast-diff deep-flatten
创建storageclass
[root@adm-master test-rbd]# cat rbd-sc.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: k8s-rbd
provisioner: ceph.com/rbd
parameters:
monitors: 192.168.0.131:6789,192.168.0.132:6789,192.168.0.133:6789
adminId: admin
adminSecretName: ceph-secret-rbd
pool: k8stest
userId: admin
userSecretName: ceph-secret-rbd
fsType: xfs
imageFormat: "2"
imageFeatures: "layering"
接着安装redis集群
第一步,按套路来先添加库。
helm repo add stable http://mirror.azure.cn/kubernetes/charts/
添加成功
[root@adm-master jenkins]# helm repo list
NAME URL
apphub https://apphub.aliyuncs.com
stable http://mirror.azure.cn/kubernetes/charts/
查询一下我们需要的redis
[root@adm-master jenkins]# helm search repo redis
NAME CHART VERSION APP VERSION DESCRIPTION
apphub/prometheus-redis-exporter 3.2.2 1.3.4 Prometheus exporter for Redis metrics
apphub/redis 10.5.3 5.0.7 Open source, advanced key-value store. It is of...
apphub/redis-cache 0.5.0 4.0.12-alpine A pure in-memory redis cache, using statefulset...
apphub/redis-ha 4.3.3 5.0.6 Highly available Kubernetes implementation of R...
apphub/redis-operator 1.0.0 Redis Operator provides high availability redis...
apphub/redispapa 0.0.1 0.0.1 利用redis的info信息对redis的使用情况进行监控的一...
stable/prometheus-redis-exporter 3.5.1 1.3.4 DEPRECATED Prometheus exporter for Redis metrics
stable/redis 10.5.7 5.0.7 DEPRECATED Open source, advanced key-value stor...
stable/redis-ha 4.4.6 5.0.6 DEPRECATED - Highly available Kubernetes implem...
stable/sensu 0.2.5 0.28 DEPRECATED Sensu monitoring framework backed by...
apphub/codis 3.2 3.2 A Helm chart for Codis
查看历史版本命令
helm search repo redis -
拉取最新的redis部署文件
helm pull stable/redis-ha
[root@adm-master src]# cd redis-ha/
[root@adm-master redis-ha]# ls
Chart.yaml ci README.md templates values.yaml
部署文件的变量值一般保存在values.yaml里面
修改一下子values.yaml里面的副本数
改为一主一从即可
存储方式改为rbd,具体搭建cephfs的方式参考我之前的文档。
部署redis集群
[root@adm-master redis-ha]# kubectl create ns test-redis
namespace/test-redis created
[root@adm-master redis-ha]# helm install redis . -f ./values.yaml -n test-redis
WARNING: This chart is deprecated
NAME: redis
LAST DEPLOYED: Sun Mar 14 22:55:28 2021
NAMESPACE: test-redis
STATUS: deployed
REVISION: 1
NOTES:
Redis can be accessed via port 6379 and Sentinel can be accessed via port 26379 on the following DNS name from within your cluster:
redis-redis-ha.test-redis.svc.cluster.local
To connect to your Redis server:
1. Run a Redis pod that you can use as a client:
kubectl exec -it redis-redis-ha-server-0 sh -n test-redis
2. Connect using the Redis CLI:
redis-cli -h redis-redis-ha.test-redis.svc.cluster.local
暴露出外网
[root@adm-master redis-ha]# cat redis-services.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-ha-service
namespace: test-redis #名称:随意
labels:
app: redis #部署的 redis-ha 名称
spec:
ports:
- name: redis #部署的 redis-ha 名称
protocol: "TCP" #TCP 协议
port: 26379
targetPort: 6379
nodePort: 30379 #此为外部连接k8s redis-ha 服务的端口
selector:
statefulset.kubernetes.io/pod-name: redis-redis-ha-server-0
type: NodePort
其他可用的命令有
redis 的 upgrade
修改了 values.yaml中的 replicas 数量之后需要更新一下
helm upgrade redis .
查看历史记录回滚
helm -n redis history
删除项目
helm uninstall redis