Kubernetes 安裝Redis集群


一、Operator

https://github.com/operator-framework/awesome-operators

 

二、安裝Redis集群的operator

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

# kubectl create -f deploy/crds/redis.kun_distributedredisclusters_crd.yaml

# kubectl create -f deploy/crds/redis.kun_redisclusterbackups_crd.yaml

  

以集群模式安裝

# 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.yam

  可以在service_account和 operator后面加-n 參數指定namespace

 

三、創建redis集群

kubectl apply -f deploy/example/redis.kun_v1alpha1_distributedrediscluster_cr.yaml

這個yaml文件中使用的資源較高,測試環境可能起不來,可以換一個

kubectl create -f deploy/example/custom-resources.yaml

  

查看Pod

# kubectl get pods
NAME                                      READY   STATUS    RESTARTS   AGE
drc-example-distributedrediscluster-0-0   1/1     Running   0          3m33s
drc-example-distributedrediscluster-0-1   1/1     Running   0          2m59s
drc-example-distributedrediscluster-1-0   1/1     Running   0          3m33s
drc-example-distributedrediscluster-1-1   1/1     Running   0          2m54s
drc-example-distributedrediscluster-2-0   1/1     Running   0          3m33s
drc-example-distributedrediscluster-2-1   1/1     Running   0          2m59s

  通過節點 親和性,確保redis分布在不同節點上

 

查看service

# kubectl get svc
NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)              AGE
example-distributedrediscluster     ClusterIP   10.106.160.212   <none>        6379/TCP,16379/TCP   4m14s
example-distributedrediscluster-0   ClusterIP   None             <none>        6379/TCP,16379/TCP   4m15s
example-distributedrediscluster-1   ClusterIP   None             <none>        6379/TCP,16379/TCP   4m15s
example-distributedrediscluster-2   ClusterIP   None             <none>        6379/TCP,16379/TCP   4m15s

  應用程序可以使用example-distributedrediscluster來連接集群

 

四、自定義Redis集群配置

custom-redis.yaml

apiVersion: v1
kind: Secret
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: mysecret
type: Opaque
data:
  password: MWYyZDFlMmU2N2Rm
---
apiVersion: redis.kun/v1alpha1
kind: DistributedRedisCluster
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: example-distributedrediscluster
spec:
  image: redis:5.0.4-alpine
  masterSize: 3
  clusterReplicas: 1
  passwordSecret:
      name: mysecret
  resources:
    limits:
      cpu: 200m
      memory: 200Mi
    requests:
      cpu: 200m
      memory: 100Mi
  storage:
    type: persistent-claim
    size: 1Gi
    class: rook-ceph-block
    deleteClaim: true

  

  • password是以base64加密的,並以環境變量的形式注入Pod中

  • 需要提前創建storageClass,class即為storageclass的名稱

修改時區

# kubectl get sts
NAME                                    READY   AGE
drc-example-distributedrediscluster-0   2/2     80m
drc-example-distributedrediscluster-1   2/2     80m
drc-example-distributedrediscluster-2   2/2     80m

  

修改statefulset,volumeMounts和volumes

省略其他配置信息

        volumeMounts:
        - mountPath: /usr/share/zoneinfo/Asia/Shanghai
          name: tz-config
        - mountPath: /etc/localtime
          name: tz-config
          
          
      volumes:
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
          type: ""
        name: tz-config

  查看

kubectl exec -it drc-example-distributedrediscluster-0-1 -- date
Thu Oct 29 16:45:50 CST 2020

redis-cli -a 1f2d1e2e67df

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM