Giter Site home page Giter Site logo

redis-in-k8s's Introduction

Redis in Kubernetes(k8s)


这是一个帮助你在Kubernetes(K8S)环境中搭建redis集群和哨兵模式的样例。

相比于其他github上的项目,优势 1. 有集群和哨兵 2种模式 2.集群模式和哨兵模式都支持扩容 3.稳定性更强,本项目支持redis持久化

这里有三个文件夹目录和若干yaml配置文件,他们都是来帮助搭建redis环境的。(如果需要使用statefulset,请将你的k8s版本提升至1.5以上~,还需要有dns组件)

images 文件夹中包含了一个Dockerfile,你可以使用一下命令来创建镜像。语法请参考搜索Docker。redis环境启动规则在run_new.sh 脚本中。

docker build -t $YOUR_TAG .

k8s_installer 是一个在单节点上安装kubernetes的脚本。使用这个脚本你首先得能连网,因为我没有把其中的rpm包全部下载下来。

redis_cluster_installer 是一个在CentOS 7 下搭建redis集群的脚本,后续我会优化。


对redis-trib.rb 的修改 2018-01-31

为 add-node 添加一个auto 命令
当目前集群中的master都有从节点时,添加的节点为master
当目前集群中至少存在一个master没有从节点时,添加的节点为slave

redis-trib.rb add-node --auto new_host:new_port existing_host:existing_port

为 info 添加一个 detail 命令,使其能够输出完整的集群信息

redis-trib.rb info --detail host:port


目前我所遇到的问题

目前所有问题都已经解决

  • kubernetes (k8s) 集群外如何访问 pod内的Redis?
    • 添加 NodePort Service ?这是不够的,因为当使用redis集群模式的时候,set 或者 get 或者其他操作,可能会重定向到其他pod,这时你可能会注意到,我用run_new.sh 搭建的集群使用的时headless service,它会重定向到一个集群内的ip,这时候怎么办? 解决办法1.尝试使用其他网络组件 解决办法2.让pod使用node借点的网络配置。给pod添加以下两个属性即可。
            hostNetwork: true
            dnsPolicy: ClusterFirstWithHostNet
    
  • 当使用redis集群模式的时候,动态扩容问题?
    • 这个问题已经在2018-02-02 解决,缩容不支持,只支持扩容

在K8S中的性能损耗

使用 redis-cli -h $ip -p port --latency 命令可以看到网络延时,性能损耗主要在网络和持久化策略上~
这个需要靠各位同志自己优化了,如果我以后有好的方案,我会继续更新到这个地址的。


shell 脚本 ^M 错误?

记得在打镜像之前先格式化下shell脚本
step1: vi or vim
step2: set ff=unix
step3: 保存

yaml 解释一波~

启动时没有顺序影响,需要什么模式就使用对应的yaml进行kubectl create 就行

sts 表示statefulset svc 表示service

  • sentinel 所需:

    • sts-redis-master.yaml
    • sts-redis-slave.yaml
    • sts-redis-sentinel.yaml
    • svc-redis-master.yaml
    • svc-redis-slave.yaml
    • svc-redis-sentinel.yaml
  • cluster 所需:

    • sts-redis-cluster.yaml
    • sts-redis-cc.yaml
    • svc-redis-cluster.yaml
    • svc-redis-cc.yaml
    • svc-redis-cluster-nodeport.yaml

2018 02 08 新增svc-redis-cluster-nodeport.yaml

为了方便集群内访问redis,并充分利用k8s环境,添加了一个普通的service

java 代码使用示例(jedis)如下:
     Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();

    jedisClusterNodes.add(new HostAndPort("svc-redis-cluster-np", 6379));

    JedisCluster jc = new JedisCluster(jedisClusterNodes);
redis宿主机上启动
Feb 03 10:13:40 master redis-server[115685]: *** FATAL CONFIG FILE ERROR ***
Feb 03 10:13:40 master redis-server[115685]: Reading the configuration file, at line 3
Feb 03 10:13:40 master redis-server[115685]: >>> 'logfile "/home/redis/log/redis.log"'
Feb 03 10:13:40 master redis-server[115685]: Can't open the log file: Permission denied
Feb 03 10:13:40 master systemd[1]: redis.service: main process exited, code=exited, status=1/FAILURE

遇到这个问题一般都是用systemctl start redis的时候遇到的,问题原因目前发现可能有两个,1 /home/redis 的目录权限 2 开启了selinux,对这个东西不懂啊~
原因1解决办法: chmod 或者chown ,这个不细讲了 原因2解决办法: setenfore 0


如有疑问,请联系我:

redis-in-k8s's People

Contributors

cqyisbug avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.