aws eks fargate 使用 efs 部署 nacos

2022-05-19  本文已影响0人  国服最坑开发

0x01 目的

在集群中以单机模式部署nacos,使用外部存储, 实现 fargate实例重启后, 配置依然可用. 

0x02 使用efs做为pv

参考: 这里

kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/deploy/kubernetes/base/csidriver.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: efs-sc
provisioner: efs.csi.aws.com
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
apiVersion: v1
items:
- 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

后续外部访问信息, 这里不再赘述.

上一篇 下一篇

猜你喜欢

热点阅读