开发者openshift4使用入门教程 - 12 - 部署redis - 哨兵模式

2022-04-21 14:17:13 浏览数 (1)

  • 一 概述
  • 二 Redis 哨兵模式部署
    • 2.1 创建 Redis CRD
    • 2.2 部署Redis 哨兵模式

一 概述

一句话总结本文内容:

如何将以下 Redis sentinel哨兵模式 部署到OpenShift 4.

二 Redis 哨兵模式部署

Abstract

使用K8S Operator 进行部署

具体使用的Operator为: ucloud/redis-operator

2.1 创建 Redis CRD

Abstract

推荐读者人群: 容器云管理员

整个容器云级别只需要做一次, 目前已经做了.

部署redis operator

命令概述:

代码语言:javascript复制
git clone https://github.com/ucloud/redis-operator.git
cd redis-operator

make REGISTRY=default-route-openshift-image-registry.caas.example.com/default build-image
make REGISTRY=default-route-openshift-image-registry.caas.example.com/default push

oc project default
oc apply -f deploy/crds/redis_v1beta1_rediscluster_crd.yaml

sed -i 's|REPLACE_IMAGE|image-registry.openshift-image-registry.svc:5000/default/redis-operator|g' deploy/cluster/operator.yaml

oc create -f deploy/service_account.yaml
oc create -f deploy/cluster/cluster_role.yaml
oc create -f deploy/cluster/cluster_role_binding.yaml
oc create -f deploy/cluster/operator.yaml

这会创建一个deployment: redis-operator. 验证方式:

代码语言:javascript复制
$ oc get deployment
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
redis-operator   1/1     1            1           65d

2.2 部署Redis 哨兵模式

Abstract

推荐读者: 开发, 项目管理, 容器云管理员.

将Operator 部署到Kubernetes集群中后,将可以使用新的API,因此您可以创建,更新和删除RedisCluster

为了部署新的RedisCluster ,必须创建一个yaml, 如: redis-cluster.yaml:

代码语言:javascript复制
apiVersion: redis.kun/v1beta1
kind: RedisCluster
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: redis
spec:
  # Add fields here
  size: 3
  # custom password (null to disable)
  password: sdnfaldngowe
  resources:
    limits:
      cpu: 400m
      memory: 246Mi
    requests:
      cpu: 100m
      memory: 256Mi
  storage:
    # By default, the persistent volume claims will be deleted when the Redis Cluster be delete.
    # If this is not the expected usage, a keepAfterDeletion flag can be added under the storage section
    keepAfterDeletion: true
    persistentVolumeClaim:
      metadata:
        name: redis
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
        storageClassName: nfs
        volumeMode: Filesystem

然后应用:

代码语言:javascript复制
oc apply -f redis-cluster.yaml

这个Redis 集群将由Operator 管理,从而在Kubernetes中创建以下元素:

  • redis-cluster-: Redis statefulset
  • redis-sentinel-: Sentinel statefulset
  • redis-sentinel-: Sentinel service
  • redis-sentinel-headless-: Sentinel headless service
  • redis-cluster-: Redis headless service

验证:

代码语言:javascript复制
$ oc get rediscluster
NAME   SIZE   STATUS    AGE
test   3      Healthy   4m9s

$ oc get all -l app.kubernetes.io/managed-by=redis-operator
NAME                        READY   STATUS    RESTARTS   AGE
pod/redis-cluster-test-0    1/1     Running   0          4m16s
pod/redis-cluster-test-1    1/1     Running   0          3m22s
pod/redis-cluster-test-2    1/1     Running   0          2m40s
pod/redis-sentinel-test-0   1/1     Running   0          4m16s
pod/redis-sentinel-test-1   1/1     Running   0          81s
pod/redis-sentinel-test-2   1/1     Running   0          18s

NAME                                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)     AGE
service/redis-cluster-test             ClusterIP   None            <none>        6379/TCP    4m16s
service/redis-sentinel-headless-test   ClusterIP   None            <none>        26379/TCP   4m16s
service/redis-sentinel-test            ClusterIP   10.22.22.34     <none>        26379/TCP   4m16s

NAME                                   READY   AGE
statefulset.apps/redis-cluster-test    3/3     4m16s
statefulset.apps/redis-sentinel-test   3/3     4m16s

查看事件和状态:

代码语言:javascript复制
$ oc describe redisclusters test

Name:         test
Namespace:    default
Labels:       <none>
Annotations:  redis.kun/scope: cluster-scoped
API Version:  redis.kun/v1beta1
Kind:         RedisCluster
Metadata:
  Generation:          1
  UID:                 ec0c3be4-b9c5-11e9-8191-6c92bfb35d2e
Spec:
  Image:              redis:5.0.4-alpine
  Resources:
    Limits:
      Cpu:     400m
      Memory:  300Mi
    Requests:
      Cpu:     100m
      Memory:  50Mi
  Size:        3
Status:
  Conditions:
    Last Transition Time:  2019-08-08T10:21:14Z
    Last Update Time:      2019-08-08T10:22:14Z
    Message:               Cluster ok
    Reason:                Cluster available
    Status:                True
    Type:                  Healthy
    Last Transition Time:  2019-08-08T10:18:53Z
    Last Update Time:      2019-08-08T10:18:53Z
    Message:               Bootstrap redis cluster
    Reason:                Creating
    Status:                True
    Type:                  Creating
Events:
  Type    Reason        Age                    From            Message
  ----    ------        ----                   ----            -------
  Normal  Creating      3m22s                  redis-operator  Bootstrap redis cluster
  Normal  Ensure        2m12s (x8 over 3m22s)  redis-operator  Makes sure of redis cluster ready
  Normal  CheckAndHeal  2m12s (x8 over 3m22s)  redis-operator  Check and heal the redis cluster problems
  Normal  Updating      2m12s (x8 over 3m22s)  redis-operator  wait for all redis server start

Quote

更多示例配置见GitHub地址

0 人点赞