日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

通过operator部署redis集群(ucloud版)

發(fā)布時(shí)間:2025/1/21 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过operator部署redis集群(ucloud版) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

operator部署有狀態(tài)的應(yīng)用會(huì)簡(jiǎn)單很多

github文檔:https://github.com/ucloud/redis-cluster-operator#deploy-redis-cluster-operator

Redis Cluster Operator在Kubernetes上管理Redis-Cluster集群

每個(gè)主節(jié)點(diǎn)及其從節(jié)點(diǎn)都由statefulSet管理,為每個(gè)statefulSet創(chuàng)建無頭svc,并為所有節(jié)點(diǎn)創(chuàng)建clusterIP服務(wù)。
每個(gè)有狀態(tài)集都使用PodAntiAffinity來確保主節(jié)點(diǎn)和從節(jié)點(diǎn)分散在不同的節(jié)點(diǎn)上。同時(shí),當(dāng)操作員在每個(gè)有狀態(tài)集中選擇主節(jié)點(diǎn)時(shí),它會(huì)優(yōu)先選擇具有不同k8s節(jié)點(diǎn)的容器作為主節(jié)點(diǎn)。

(1)下載redis-cluster-operator

git clone https://github.com/ucloud/redis-cluster-operator.git

在名稱空間:redis-cluster下部署Redis集群,注意修改yaml文件的namespace參數(shù)
創(chuàng)建名稱空間Namespace:redis-cluster

[root@k8s-master01 redis-cluster-operator-master]# kubectl create ns redis-cluster namespace/redis-node created [root@k8s-master01 redis-cluster-operator-master]# kubectl get ns NAME STATUS AGE default Active 76d ingress-nginx Active 9d kube-node-lease Active 76d kube-public Active 76d kube-system Active 76d kube-users Active 2d21h kubernetes-dashboard Active 45h redis-cluster Active 11s rook-ceph Active 33h [root@k8s-master01 redis-cluster-op

(2)創(chuàng)建自定義資源(CRD)

[root@k8s-master01 redis]# kubectl apply -f deploy/crds/ customresourcedefinition.apiextensions.k8s.io/distributedredisclusters.redis.kun created customresourcedefinition.apiextensions.k8s.io/redisclusterbackups.redis.kun created

(3)創(chuàng)建operator

[root@k8s-master01 redis]# kubectl create -f deploy/service_account.yaml serviceaccount/redis-cluster-operator created [root@k8s-master01 redis]# kubectl create -f deploy/cluster/cluster_role.yaml clusterrole.rbac.authorization.k8s.io/redis-cluster-operator created [root@k8s-master01 redis]# kubectl create -f deploy/cluster/cluster_role_binding.yaml clusterrolebinding.rbac.authorization.k8s.io/redis-cluster-operator created [root@k8s-master01 redis]# kubectl create -f deploy/cluster/operator.yaml deployment.apps/redis-cluster-operator created configmap/redis-admin created [root@k8s-master01 redis]# kubectl get deployment NAME READY UP-TO-DATE AVAILABLE AGE metrics-metrics-server 1/1 1 1 10d redis-cluster-operator 1/1 1 1 12s// cluster-scoped 命令 $ kubectl create -f deploy/service_account.yaml $ kubectl create -f deploy/cluster/cluster_role.yaml $ kubectl create -f deploy/cluster/cluster_role_binding.yaml $ kubectl create -f deploy/cluster/operator.yaml

(4)部署樣本Redis集群

注意:只有使用持久性存儲(chǔ)(pvc)的redis集群在意外刪除或滾動(dòng)更新后才能恢復(fù)。即使您不使用持久性(如rdb或aof),也需要將pvc設(shè)置為redis。

apiVersion: redis.kun/v1alpha1 kind: DistributedRedisCluster metadata:annotations:# if your operator run as cluster-scoped, add this annotationsredis.kun/scope: cluster-scopedname: example-distributedrediscluster spec:image: redis:5.0.4-alpinemasterSize: 3clusterReplicas: 1resources:limits:cpu: 200mmemory: 200Mirequests:cpu: 200mmemory: 100Mi

因?yàn)槭褂脴颖?#xff0c;沒有資源限制,會(huì)因?yàn)閮?nèi)存不足導(dǎo)致初始化失敗,限制使用這個(gè)測(cè)試

kubectl create -f deploy/example/custom-resources.yaml [root@k8s-master01 redis]# kubectl get pod,svc NAME READY STATUS RESTARTS AGE pod/drc-example-distributedrediscluster-0-0 1/1 Running 0 6m39s pod/drc-example-distributedrediscluster-0-1 1/1 Running 0 6m2s pod/drc-example-distributedrediscluster-1-0 1/1 Running 0 6m39s pod/drc-example-distributedrediscluster-1-1 1/1 Running 0 6m7s pod/drc-example-distributedrediscluster-2-0 1/1 Running 0 6m39s pod/drc-example-distributedrediscluster-2-1 1/1 Running 0 6m6s pod/metrics-metrics-server-6c7745d876-cw72h 1/1 Running 0 8h pod/redis-cluster-operator-7f6cf86475-dhttx 1/1 Running 0 11mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/example-distributedrediscluster ClusterIP 10.96.104.199 <none> 6379/TCP,16379/TCP 6m38s service/example-distributedrediscluster-0 ClusterIP None <none> 6379/TCP,16379/TCP 6m38s service/example-distributedrediscluster-1 ClusterIP None <none> 6379/TCP,16379/TCP 6m38s service/example-distributedrediscluster-2 ClusterIP None <none> 6379/TCP,16379/TCP 6m38s service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 76d service/metrics-metrics-server ClusterIP 10.96.86.164 <none> 443/TCP 10d service/nginx ClusterIP 10.96.215.251 <none> 80/TCP 9d service/redis-cluster-operator-metrics ClusterIP 10.96.58.127 <none> 8383/TCP,8686/TCP 11m [root@k8s-master01 redis]#

創(chuàng)建指定命名空間和動(dòng)態(tài)存儲(chǔ)的,我這個(gè)沒有構(gòu)建動(dòng)態(tài)存儲(chǔ)

cat redis-cluster.yaml apiVersion: redis.kun/v1alpha1 kind: DistributedRedisCluster metadata:annotations:# if your operator run as cluster-scoped, add this annotationsredis.kun/scope: cluster-scopedname: example-distributedredisclusternamespace: redis-cluster spec:image: redis:5.0.4-alpineimagePullPolicy: IfNotPresentmasterSize: 3 #master節(jié)點(diǎn)數(shù)量clusterReplicas: 1 #每個(gè)master節(jié)點(diǎn)的從節(jié)點(diǎn)數(shù)量serviceName: redis-svc# resources configresources:limits:cpu: 300mmemory: 200Mirequests:cpu: 200mmemory: 150Mi# pv storagestorage:type: persistent-claimsize: 2Giclass: nfs-storagedeleteClaim: true ]# kubectl apply -f redis-cluster.yaml

(5)驗(yàn)證集群

[root@k8s-master01 redis]# kubectl exec -it drc-example-distributedrediscluster-0-0 -- sh /data # redis-cli -c -h redis-svc Could not connect to Redis at redis-svc:6379: Name does not resolve not connected> /data # redis-cli -c -h example-distributedrediscluster example-distributedrediscluster:6379> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:5 cluster_my_epoch:0 cluster_stats_messages_ping_sent:511 cluster_stats_messages_pong_sent:485 cluster_stats_messages_meet_sent:1 cluster_stats_messages_sent:997 cluster_stats_messages_ping_received:481 cluster_stats_messages_pong_received:512 cluster_stats_messages_meet_received:4 cluster_stats_messages_received:997 example-distributedrediscluster:6379> set a b -> Redirected to slot [15495] located at 10.244.58.209:6379 OK 10.244.58.209:6379>

(6)擴(kuò)展Redis集群

增加masterSize觸發(fā)放大。(注意:這個(gè)也直接可以使用edit修改。)

apiVersion: redis.kun/v1alpha1 kind: DistributedRedisCluster metadata:annotations:# if your operator run as cluster-scoped, add this annotationsredis.kun/scope: cluster-scopedname: example-distributedrediscluster spec:# Increase the masterSize to trigger the scaling.masterSize: 4ClusterReplicas: 1image: redis:5.0.4-alpine

(7)縮減Redis集群

減小masterSize觸發(fā)縮小。

apiVersion: redis.kun/v1alpha1 kind: DistributedRedisCluster metadata:annotations:# if your operator run as cluster-scoped, add this annotationsredis.kun/scope: cluster-scopedname: example-distributedrediscluster spec:# Increase the masterSize to trigger the scaling.masterSize: 3ClusterReplicas: 1image: redis:5.0.4-alpine

(8)刪除redis集群

]# cd redis-cluster-operator/ ]# kubectl delete -f redis-cluster.yaml ]# cd cluster/ ]# kubectl delete -f operator.yaml ]# kubectl delete -f cluster_role_binding.yaml ]# kubectl delete -f cluster_role.yaml ]# kubectl delete-f service_account.yaml ]# kubectl delete -f deploy/crds/ ]# kubectl delete -f ns-redis-cluster.yaml

github文檔:https://github.com/ucloud/redis-cluster-operator#deploy-redis-cluster-operator

參考鏈接:https://www.cnblogs.com/heian99/p/14508307.html

總結(jié)

以上是生活随笔為你收集整理的通过operator部署redis集群(ucloud版)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。