0x00 前言
本篇文章总结下,项目背景是需要在 Kubernetes 集群中部署 Redis 单机 / 集群,需要利用 Statefulsets
与 NFS
来生成。
0x01 单机 Redis 搭建
创建 ConfigMap
首先,把 Redis
的配置文件 redis.conf
存储在 configmap
中,注意其中定义的 Redis
运行目录:/data/middleware-data/redis/
apiVersion: v1
data:
redis.conf: |
bind 0.0.0.0
port 6379
requirepass xxxxxx
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
kind: ConfigMap
metadata:
creationTimestamp: "2021-06-27T10:01:29Z"
name: redis-conf
namespace: xxxx
创建 StatefulSet
创建 StatefulSet
,并把数据挂载到宿主机上。注意,我们使用 initContainers
来完成前置工作,如目录创建等;
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
creationTimestamp: "2021-06-27T10:03:08Z"
generation: 1
name: redis
namespace: xxxx
spec:
podManagementPolicy: OrderedReady
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
name: redis
serviceName: redis
template:
metadata:
creationTimestamp: null
labels:
name: redis
spec:
containers:
- command:
- sh
- -c
- exec redis-server /data/middleware-data/redis/conf/redis.conf
image: redis:5.0.6
imagePullPolicy: IfNotPresent
name: redis
ports:
- containerPort: 6379
name: redis
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /data/middleware-data/redis/conf/
name: redis-config
- mountPath: /data/middleware-data/redis/
name: data
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- mkdir -p /data/middleware-data/redis/log/;mkdir -p /data/middleware-data/redis/conf/;mkdir -p /data/middleware-data/redis/data/
image: busybox
imagePullPolicy: Always
name: init-redis
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /data/middleware-data/redis/
name: data
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
name: redis-conf
name: redis-config
- hostPath:
path: /data/middleware-data/redis/
type: ""
name: data
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
创建 Service
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2021-06-27T10:03:44Z"
labels:
name: redis
name: redis
namespace: xxxx
spec:
clusterIP: 172.16.255.66
externalTrafficPolicy: Cluster
ports:
- name: redis
nodePort: 30020
port: 6379
protocol: TCP
targetPort: 6379
selector:
name: redis
sessionAffinity: None
type: NodePort
0x02 Redis 集群搭建
第一步:创建 NFS 存储
创建 PV
创建 PVC
使用 NFS 配置 StatefulSet 的动态持久化存储
创建 Configmap
创建 Headless Service
创建 Redis StatefulSet
0x03 参考
FEATURED TAGS
Latex
gRPC
负载均衡
OpenSSH
Authentication
Consul
Etcd
Kubernetes
性能优化
Python
分布式锁
WebConsole
后台开发
Golang
OpenSource
Nginx
Vault
网络安全
Perl
分布式理论
Raft
正则表达式
Redis
分布式
限流
go-redis
微服务
反向代理
ReverseProxy
Cache
缓存
连接池
OpenTracing
GOMAXPROCS
GoMicro
微服务框架
日志
zap
Pool
Kratos
Hystrix
熔断
并发
Pipeline
证书
Prometheus
Metrics
PromQL
Breaker
定时器
Timer
Timeout
Kafka
Xorm
MySQL
Fasthttp
bytebufferpool
任务队列
队列
异步队列
GOIM
Pprof
errgroup
consistent-hash
Zinx
网络框架
设计模式
HTTP
Gateway
Queue
Docker
网关
Statefulset
NFS
Machinery
Teleport
Zero Trust
Oxy
存储
Confd
热更新
OAuth
SAML
OpenID
Openssl
AES
微服务网关
IM
KMS
安全
数据结构
hashtable
Sort
Asynq
基数树
Radix
Crontab
热重启
系统编程
sarama
Go-Zero
RDP
VNC
协程池
UDP
hashmap
网络编程
自适应技术
环形队列
Ring Buffer
Circular Buffer
InnoDB
timewheel
GroupCache
Jaeger
GOSSIP
CAP
Bash
websocket
事务
GC
TLS
singleflight
闭包
Helm
network
iptables
MITM
HTTPS
Tap
Tun
路由
wireguard
gvisor
Git
NAT
协议栈
Envoy
FRP
DPI
gopacket
Cgroup
Namespace
DNS
eBPF
GoZero
Gost
Clash
gopsutil
HIDS
ELKEID
XDP
TC
Linux