k3s安装redis

配置文件如下:

1. 首先,通过ConfigMap来对容器中redis应用的配置进行管理,如自定义配置文件、密码、日志路径等

apiVersion: v1
kind: ConfigMap
metadata:
 name: redis-standalone-conf
data:
 redis.conf: |
 bind 0.0.0.0
 port 6379
 appendonly yes
 cluster-config-file nodes-6379.conf
 pidfile /redis/log/redis-6379.pid
 cluster-config-file /redis/conf/redis.conf
 dir /redis/data/
 logfile /redis/log/redis-6379.log
 cluster-node-timeout 5000
 protected-mode no

2.由于redis是一个有状态服务,因此,现需要创建一个StatefulSet,并把数据挂载到宿主机上。

apiVersion: apps/v1
kind: StatefulSet
metadata:
 name: redis-standalone
spec:
 replicas: 1
 serviceName: redis-standalone
 selector:
 matchLabels:
 name: redis-standalone
 template:
 metadata:
 labels:
 name: redis-standalone
 spec:
 initContainers:
 - name: init-redis-standalone
 image: busybox
 command: ['sh', '-c', 'mkdir -p /redis/log/;mkdir -p /redis/conf/;mkdir -p /redis/data/']
 volumeMounts:
 - name: data
 mountPath: /redis/
 containers:
 - name: redis-standalone
 image: redis:5.0.6
 imagePullPolicy: IfNotPresent
 command:
 - sh
 - -c
 - "exec redis-server /redis/conf/redis.conf"
 ports:
 - containerPort: 6379
 name: redis
 protocol: TCP
 volumeMounts:
 - name: redis-config
 mountPath: /redis/conf/
 - name: data
 mountPath: /redis/
 volumes:
 - name: redis-config
 configMap:
 name: redis-standalone-conf
 - name: data
 hostPath:
 path: /redis/
3.创建statefulset
kind: Service
apiVersion: v1
metadata:
 labels:
 name: redis-standalone
 name: redis-standalone
spec:
 type: NodePort
 ports:
 - name: redis
 port: 6379
 targetPort: 6379
 nodePort: 31379
 selector:
 name: redis-standalone

连接redis的31379端口即可
参考地址:https://zhuanlan.zhihu.com/p/160959892

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值