zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    Jmeter----读取excel表中的数据
    Jmeter-----【mac电脑】配置web浏览器的代理抓取请求
    Git----GitHub上传本地文件到git
    Postman----Newman的使用
    Postman----安装Newman
    Postman----设置代理抓取手机上的请求
    postman-----使用CSV和Json文件实现批量接口测试
    【已解决】【Mac】 运行adb提示command not found,需要配置adb环境
    浅析Java中的final关键字
    git branch简单使用
  • 原文地址:https://www.cnblogs.com/bigberg/p/13926174.html
Copyright © 2011-2022 走看看