kubernetes部署redis5.0.6单机版 自定义配置文件、密码、日志路径等
创建redis配置configmaps:
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-conf
data:
redis.conf: |
bind 0.0.0.0
port 6379
requirepass 123456
pidfile .pid
appendonly yes
cluster-config-file nodes-6379.conf
pidfile /data/middleware-data/redis/log/redis-6379.pid
cluster-config-file /data/middleware-data/redis/conf/redis.conf
dir /data/middleware-data/redis/data/
logfile "/data/middleware-data/redis/log/redis-6379.log"
cluster-node-timeout 5000
protected-mode no
创建StatefulSet,并把数据挂载到宿主机上:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
replicas: 1
serviceName: redis
selector:
matchLabels:
name: redis
template:
metadata:
labels:
name: redis
spec:
initContainers:
- name: init-redis
image: busybox
command: ['sh', '-c', 'mkdir -p /data/middleware-data/redis/log/;mkdir -p /data/middleware-data/redis/conf/;mkdir -p /data/middleware-data/redis/data/']
volumeMounts:
- name: data
mountPath: /data/middleware-data/redis/
containers:
- name: redis
image: redis:5.0.6
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- "exec redis-server /data/middleware-data/redis/conf/redis.conf"
ports:
- containerPort: 6379
name: redis
protocol: TCP
volumeMounts:
- name: redis-config
mountPath: /data/middleware-data/redis/conf/
- name: data
mountPath: /data/middleware-data/redis/
volumes:
- name: redis-config
configMap:
name: redis-conf
- name: data
hostPath:
path: /data/middleware-data/redis/
创建Service:
kind: Service
apiVersion: v1
metadata:
labels:
name: redis
name: redis
spec:
type: NodePort
ports:
- name: redis
port: 6379
targetPort: 6379
nodePort: 30020
selector:
name: redis
作者简洁
作者:小碗汤,一位热爱、认真写作的小伙,目前维护原创公众号:『我的小碗汤』,专注于写go语言、docker、kubernetes、java等开发、运维知识等提升硬实力的文章,期待你的关注。转载说明:务必注明来源(注明:来源于公众号:我的小碗汤,作者:小碗汤)