NFS做K8s存储的问题处理
起因
就是之前说的《在K8s上部署Mastodon》,因为web和sidekiq两个pod都需要读写public路径,所以当时用了NFS来配置成RWX模式的PV/PVC给它们用。但实际使用下来发现稳定性不行。
AI的解释是:
NFS 的协议特性、高并发网络 I/O 以及 K8s 的动态编排机制 产生了冲突。
推荐的解决方案是:用Ceph这样的云存储方案或Rancher的Local path provisioner这样的本地存储方案。
但是Ceph过于笨重了,我的K8s环境又不是用RKE装的,也懒得再去搞LPP,所以改为最简单的方案hostPath吧。
解决方案
修改mastodon的service配置文件,以web服务为例,如svc_mastodon_web.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mastodon-web
namespace: mastodon
labels:
app: mastodon
component: web
spec:
replicas: 1
selector:
matchLabels:
app: mastodon
component: web
template:
metadata:
labels:
app: mastodon
component: web
spec:
containers:
- name: mastodon-web
image: ghcr.io/mastodon/mastodon:v4.5.2
command: ["bash", "-c", "rm -f /mastodon/tmp/pids/server.pid; bundle exec puma -C config/puma.rb"]
ports:
- containerPort: 3000
envFrom:
- secretRef:
name: mastodon-env
resources:
requests:
cpu: "500m"
memory: "1Gi"
limits:
cpu: "2"
memory: "2Gi"
volumeMounts:
- name: mastodon-data-web
mountPath: /mastodon/public/system
livenessProbe:
exec:
command:
- curl
- -s
- --noproxy
- localhost
- localhost:3000/health
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
exec:
command:
- curl
- -s
- --noproxy
- localhost
- localhost:3000/health
initialDelaySeconds: 5
periodSeconds: 10
volumes:
- name: mastodon-data-web
hostPath:
path: /var/data/mastodon
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: mastodon-web
namespace: mastodon
labels:
app: mastodon
component: web
spec:
type: NodePort
selector:
app: mastodon
component: web
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30300
其中的关键就是把volumes配置从原来的nfs pvc换成了hostPath。单节点就是这点好,比如那个nodePort也是,外面加个nginx反代一下就好了,也不用什么ingress。
推送到[go4pro.org]