k8s快速部署Redis单机
1.创建Redis配置
apiVersion: v1
data:
redis.conf: |-
bind 0.0.0.0
port 6379
requirepass System@123
pidfile /var/run/redis_6379.pid
save 900 1
save 300 10
save 60 10000
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
dir /data
logfile "/data/redis-6379.log"
kind: ConfigMap
metadata:
name: redis-config
namespace: ops-share
2.创建PV/PVC
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: redis-data namespace: ops-share spec: storageClassName: nfs-client #使用存储类自行替换,不是根据时间情况创建 accessModes: - ReadWriteMany resources: requests: storage: 10G
3.创建redis deployment文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: t1-redis
namespace: ops-share
spec:
replicas: 1
selector:
matchLabels:
app: t1-redis
template:
metadata:
labels:
app: t1-redis
spec:
containers:
- image: redis:6.0.9
command: ["redis-server","/etc/redis/redis.conf"]
name: t1-redis
ports:
- containerPort: 6379
volumeMounts:
- name: redis-config
mountPath: /etc/redis/redis.conf
subPath: redis.conf
- name: redis-data
mountPath: /data
volumes:
- name: redis-config
configMap:
name: redis-config
- name: redis-data
persistentVolumeClaim:
claimName: redis-data
4.创建Redis svc文件
apiVersion: v1
kind: Service
metadata:
labels:
app: t1-redis-svc
name: t1-redis-svc
namespace: ops-share
spec:
ports:
- name: tcp-redis-6379
port: 6379
protocol: TCP
targetPort: 6379
selector:
app: t1-redis
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少