首次提交:初始化项目
This commit is contained in:
17
010-中间件/001-redis/deploy.sh
Normal file
17
010-中间件/001-redis/deploy.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 创建命名空间
|
||||
kubectl create namespace redis
|
||||
|
||||
# 部署 Redis
|
||||
kubectl apply -f redis-deployment.yaml
|
||||
|
||||
# 等待 Redis 启动
|
||||
echo "等待 Redis 启动..."
|
||||
kubectl wait --for=condition=ready pod -l app=redis -n redis --timeout=300s
|
||||
|
||||
# 显示状态
|
||||
echo "Redis 部署完成!"
|
||||
kubectl get pods -n redis
|
||||
kubectl get pvc -n redis
|
||||
kubectl get svc -n redis
|
||||
52
010-中间件/001-redis/readme.md
Normal file
52
010-中间件/001-redis/readme.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Redis 部署说明
|
||||
|
||||
## 配置信息
|
||||
|
||||
- **命名空间**: redis
|
||||
- **存储**: 使用 Longhorn 提供 5Gi 持久化存储
|
||||
- **镜像**: redis:7-alpine
|
||||
- **持久化**: 启用 RDB + AOF 双重持久化
|
||||
- **内存限制**: 2GB
|
||||
- **访问地址**: redis.redis.svc.cluster.local:6379
|
||||
|
||||
## 部署方式
|
||||
|
||||
```bash
|
||||
bash deploy.sh
|
||||
```
|
||||
|
||||
## 持久化配置
|
||||
|
||||
### RDB 快照
|
||||
- 900秒内至少1个key变化
|
||||
- 300秒内至少10个key变化
|
||||
- 60秒内至少10000个key变化
|
||||
|
||||
### AOF 日志
|
||||
- 每秒同步一次
|
||||
- 自动重写阈值: 64MB
|
||||
|
||||
## 内存策略
|
||||
|
||||
- 最大内存: 2GB
|
||||
- 淘汰策略: allkeys-lru (所有key的LRU算法)
|
||||
|
||||
## 连接测试
|
||||
|
||||
在集群内部测试连接:
|
||||
|
||||
```bash
|
||||
kubectl run redis-test --rm -it --image=redis:7-alpine -- redis-cli -h redis.redis.svc.cluster.local ping
|
||||
```
|
||||
|
||||
## 备份说明
|
||||
|
||||
Redis 数据存储在 Longhorn 卷上,可以通过 Longhorn UI 创建快照和备份到 S3。
|
||||
|
||||
## 监控
|
||||
|
||||
可以通过以下命令查看 Redis 状态:
|
||||
|
||||
```bash
|
||||
kubectl exec -n redis $(kubectl get pod -n redis -l app=redis -o jsonpath='{.items[0].metadata.name}') -- redis-cli info
|
||||
```
|
||||
123
010-中间件/001-redis/redis-deployment.yaml
Normal file
123
010-中间件/001-redis/redis-deployment.yaml
Normal file
@@ -0,0 +1,123 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: redis-pvc
|
||||
namespace: redis
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
storageClassName: longhorn
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: redis-config
|
||||
namespace: redis
|
||||
data:
|
||||
redis.conf: |
|
||||
# Redis 配置
|
||||
bind 0.0.0.0
|
||||
protected-mode yes
|
||||
port 6379
|
||||
tcp-backlog 511
|
||||
timeout 0
|
||||
tcp-keepalive 300
|
||||
|
||||
# 持久化配置
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
stop-writes-on-bgsave-error yes
|
||||
rdbcompression yes
|
||||
rdbchecksum yes
|
||||
dbfilename dump.rdb
|
||||
dir /data
|
||||
|
||||
# AOF 持久化
|
||||
appendonly yes
|
||||
appendfilename "appendonly.aof"
|
||||
appendfsync everysec
|
||||
no-appendfsync-on-rewrite no
|
||||
auto-aof-rewrite-percentage 100
|
||||
auto-aof-rewrite-min-size 64mb
|
||||
|
||||
# 内存管理
|
||||
maxmemory 2gb
|
||||
maxmemory-policy allkeys-lru
|
||||
|
||||
# 日志
|
||||
loglevel notice
|
||||
logfile ""
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: redis
|
||||
namespace: redis
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: redis
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: redis
|
||||
spec:
|
||||
containers:
|
||||
- name: redis
|
||||
image: redis:7-alpine
|
||||
command:
|
||||
- redis-server
|
||||
- /etc/redis/redis.conf
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
name: redis
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
- name: config
|
||||
mountPath: /etc/redis
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "1000m"
|
||||
livenessProbe:
|
||||
tcpSocket:
|
||||
port: 6379
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- redis-cli
|
||||
- ping
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: redis-pvc
|
||||
- name: config
|
||||
configMap:
|
||||
name: redis-config
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis
|
||||
namespace: redis
|
||||
spec:
|
||||
selector:
|
||||
app: redis
|
||||
ports:
|
||||
- port: 6379
|
||||
targetPort: 6379
|
||||
protocol: TCP
|
||||
type: ClusterIP
|
||||
Reference in New Issue
Block a user