0x01 目的
在集群中以单机模式部署nacos,使用外部存储, 实现 fargate实例重启后, 配置依然可用.
0x02 使用efs做为pv
参考: 这里
- 在aws console控制台,创建一个
多区可用
efs系统,拿到文件Id:fs-xxxxx
- 在aws console控制台,创建一个
2.fargate目前已经支持efs, 如果要安装可以这样:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/deploy/kubernetes/base/csidriver.yaml
- 3.部署storage class
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
- 4.部署persistent volume
注意
: 默认nacos集群有三个节点, 下面的pv对象, 要按不同的名子,部署三次.
apiVersion: v1
kind: PersistentVolume
metadata:
name: nacos-pv-0 # 改这里 nacos-pv-1, nacos-pv-2
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc # 这里使用上面的sc名称
csi:
driver: efs.csi.aws.com
volumeHandle: <EFS filesystem ID> # 这里关联自己的efs file id
部署PV验证
# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nacos-pv-0 20Gi RWX Retain Available efs-sc 3m22s
- 5.部署PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: efs-sc
name: data-nacos-0
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
volumeName: nacos-pv-0
0x03 部署nacos
官方参考 里使用的是 NFS方式,比较繁琐.
参考文档, 编写最简单的配置部署文件.
修改后的效果如下
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nacos
namespace: prod
labels:
app: nacos
spec:
replicas: 1
template:
metadata:
name: nacos
labels:
app: nacos
spec:
containers:
- name: nacos
image: nacos/nacos-server:v2.1.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8848
name: client-port
- containerPort: 9848
name: client-rpc
- containerPort: 9849
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
env:
- name: MODE
value: standalone
resources:
requests:
cpu: 500m
memory: 1750Mi
limits:
cpu: 500m
memory: 1750Mi
volumeMounts:
- name: data
mountPath: /home/nacos/data
subPath: data
- name: data
mountPath: /home/nacos/logs
subPath: logs
volumes:
- name: data
persistentVolumeClaim:
claimName: data-nacos-0
restartPolicy: Always
selector:
matchLabels:
app: nacos
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless
namespace: prod
spec:
selector:
app: nacos
ports:
- port: 8848
targetPort: 8848
type: ClusterIP
后续外部访问信息, 这里不再赘述.