kubernetes部署高可用redis

本文redis通过helm搭建,提供redis高可用完整的编排,关于Helm的搭建和使用请查看文章《helm的搭建及使用》,其中前一章介绍了Helm搭建,并提供了Helm搭建Harbor的例子,所以本意仅做简要叙述

可根据https://github.com/bitnami/charts/tree/master/upstreamed/redis使用helm在线安装

下载到本地安装,并保存debug日志,将日志多余部分删除,保留redis的编排文件以便之后使用

git clone https://github.com/bitnami/charts.git
cd XXX/bitnami/charts/upstreamed/redis
helm install . --debug --name hub |sed 'w harbor.yaml'

作者整理可用的编排文件:
链接:https://pan.baidu.com/s/1_veDQVxQTp_tbQibynEjSQ 密码:x9l1

注意⚠️根据具体情况修改编排文件的Volume部分

 volumeClaimTemplates:
  - metadata:
      name: data
      annotations:
    spec:
      accessModes:
        - "ReadWriteOnce"
      resources:
        requests:
          storage: "5Gi"
      storageClassName: nfs

由于国内对k8s集群资料极少,本文为作者爬坑手码,如果对您有所帮助希望可以留下你的喜欢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kubernetes部署Redis高可用可以通过Redis Sentinel或Redis Cluster来实现。这里以Redis Sentinel为例,步骤如下: 1. 创建Redis Sentinel镜像 首先需要创建Redis Sentinel镜像,可以通过以下Dockerfile创建: ``` FROM redis:5.0.7-alpine RUN apk add --no-cache --update curl COPY sentinel.conf /etc/redis/sentinel.conf CMD ["redis-sentinel", "/etc/redis/sentinel.conf"] ``` 其中sentinel.conf是Redis Sentinel的配置文件,可以在其中设置Redis实例的地址、端口等信息。 2. 创建Redis StatefulSet 接着创建Redis StatefulSet,可以参考以下yaml文件: ``` apiVersion: v1 kind: Service metadata: name: redis spec: selector: app: redis ports: - name: redis port: 6379 targetPort: 6379 clusterIP: None --- apiVersion: apps/v1 kind: StatefulSet metadata: name: redis spec: serviceName: redis replicas: 3 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:5.0.7-alpine command: - redis-server - /etc/redis/redis.conf volumeMounts: - name: redis-config mountPath: /etc/redis - name: sentinel image: my-redis-sentinel:latest volumeMounts: - name: sentinel-config mountPath: /etc/redis volumes: - name: redis-config configMap: name: redis-config - name: sentinel-config configMap: name: sentinel-config volumeClaimTemplates: - metadata: name: data annotations: volume.beta.kubernetes.io/storage-class: "gp2" spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi ``` 其中,StatefulSet中有两个容器:一个是Redis容器,一个是Redis Sentinel容器。Redis容器使用Redis官方镜像,Redis Sentinel容器使用自己创建的Redis Sentinel镜像。同时,还需要创建两个ConfigMap,一个用于Redis配置,一个用于Redis Sentinel配置。 3. 部署Redis Sentinel 最后部署Redis Sentinel,可以参考以下yaml文件: ``` apiVersion: apps/v1 kind: Deployment metadata: name: redis-sentinel spec: replicas: 3 selector: matchLabels: app: redis-sentinel template: metadata: labels: app: redis-sentinel spec: containers: - name: redis-sentinel image: my-redis-sentinel:latest command: - redis-sentinel - /etc/redis/sentinel.conf volumeMounts: - name: sentinel-config mountPath: /etc/redis volumes: - name: sentinel-config configMap: name: sentinel-config ``` 通过部署Redis Sentinel,可以实现Redis集群的高可用。如果Redis主节点出现故障,Redis Sentinel会自动将从节点升级为主节点,从而保证Redis集群的可用性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值