侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 461 篇文章
  • 累计创建 184 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

K8S-FastDFS

WinJay
2024-01-13 / 0 评论 / 0 点赞 / 12 阅读 / 11373 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。

使用docker安装FastDfs分布式文件系统

PROD-HDFS

Board

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-tracker
  template:
    metadata:
      labels:
        app: fdfs-tracker
    spec:
      containers:
      - name: fdfs-tracker
        image: delron/fastdfs
        command: ["tracker"]
        securityContext:
          runAsUser: 0
        volumeMounts:
        - name: storage
          mountPath: /var/fdfs
    spec:
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: alicloud-nas

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-storage
  template:
    metadata:
      labels:
        app: fdfs-storage
    spec:
      containers:
      - name: fdfs-storage
        image: delron/fastdfs
        command: ["storage"]
        securityContext:
          runAsUser: 0
        volumeMounts:
        - name: storage
          mountPath: /var/fdfs
        - name: tracker
          mountPath: /etc/fdfs/tracker.conf
          readOnly: true
        env:
        - name: GROUP_NAME
          value: Lit
        - name: TRACKER_SERVER
           value: "fdfs-tracker.lit.svc:22122"  
    spec:
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: alicloud-nas
      - name: tracker
        configMap:
          name: fdfs-tracker

---
apiVersion: v1
kind: Service
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  selector:
    app: fdfs-tracker
  ports:
  - name: tracker
    port: 22122
    targetPort: 22122

---
apiVersion: v1
kind: Service
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  selector:
    app: fdfs-storage
  ports:
  - name: storage
    port: 23000
    targetPort: 23000
  - name: storage
    port: 23001
    targetPort: 23001



---
# Pv PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: alicloud-nas
spec:
  storageClassName: alicloud-nas
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-tracker
  template:
    metadata:
      labels:
        app: fdfs-tracker
    spec:
      containers:
      - name: fdfs-tracker
        image: delron/fastdfs
        command: ["tracker"]
        securityContext:
          runAsUser: 0
        volumeMounts:
        - name: storage
          mountPath: /var/fdfs
    spec:
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: alicloud-nas

好的,以下是修改后的 Deployment YAML 文件的详细说明:

FDFS-Tracker Deployment

  • 名称:fdfs-tracker

  • 命名空间:lit

  • 副本数:1

  • 标签选择器:app=fdfs-tracker

  • 容器

    • 名称:fdfs-tracker

    • 镜像:delron/fastdfs

    • 命令:tracker

    • 安全上下文:以 root 用户运行

    • 卷挂载

      • 名称:storage 路径:/var/fdfs 类型:persistentVolumeClaim claimName:alicloud-nas

FDFS-Tracker Service

  • 名称:fdfs-tracker

  • 命名空间:lit

  • 标签选择器:app=fdfs-tracker

  • 端口

    • 名称:tracker 端口:22122 目标端口:22122

FDFS-Storage Deployment

  • 名称:fdfs-storage

  • 命名空间:lit

  • 副本数:1

  • 标签选择器:app=fdfs-storage

  • 容器

    • 名称:fdfs-storage

    • 镜像:delron/fastdfs

    • 命令:storage

    • 安全上下文:以 root 用户运行

    • 卷挂载

      • 名称:storage 路径:/var/fdfs 类型:persistentVolumeClaim claimName:alicloud-nas

      • 名称

        :tracker 路径:/etc/fdfs/tracker.conf 只读:true env:

        • name:GROUP_NAME value:Lit

FDFS-Storage Service

  • 名称:fdfs-storage

  • 命名空间:lit

  • 标签选择器:app=fdfs-storage

  • 端口

    • 名称:storage 端口:23000 目标端口:23000
    • 名称:storage 端口:23001 目标端口:23001

修改说明

  • 修改了 Deployment 的名称和命名空间,以符合您的要求。
  • 修改了容器的卷挂载方式,使用了 persistentVolumeClaim 而不是 hostPath。
  • 添加了 Service 资源,用于暴露 Deployment 的端口。

部署

您可以使用以下命令将 YAML 文件部署到 Kubernetes 集群:

kubectl apply -f fdfs-tracker.yaml
kubectl apply -f fdfs-storage.yaml

部署完成后,您可以使用以下命令查看容器状态:

kubectl get pods -n lit

输出示例:

NAME                   READY   STATUS    RESTARTS   AGE
fdfs-tracker          1/1     Running   0          3m15s
fdfs-storage          1/1     Running   0          3m15s

验证

您可以使用以下命令验证 FastDFS 是否部署成功:

kubectl exec -it fdfs-tracker -n lit -c fdfs-tracker /bin/bash

进入容器后,您可以使用以下命令查看 tracker 的状态:

fdfs_tracker -p 22122

输出示例:

Tracker Status:
    running

如果您看到 tracker 的状态为 "running",则说明 FastDFS 部署成功。

ChatGPT

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-tracker
  template:
    metadata:
      labels:
        app: fdfs-tracker
    spec:
      containers:
      - name: fdfs-tracker
        image: delron/fastdfs:tracker
        command: ["/bin/sh", "-c"]
        args:
        - |
          /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
        volumeMounts:
        - name: fdfs-tracker-storage
          mountPath: /var/fdfs
      restartPolicy: Always
      serviceAccountName: default
  volumes:
  - name: fdfs-tracker-storage
    emptyDir: {}

---

apiVersion: v1
kind: Service
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  selector:
    app: fdfs-tracker
  ports:
  - protocol: TCP
    port: 22122
    targetPort: 22122
  - protocol: TCP
    port: 23000
    targetPort: 23000
  type: ClusterIP

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-storage
  template:
    metadata:
      labels:
        app: fdfs-storage
    spec:
      containers:
      - name: fdfs-storage
        image: delron/fastdfs:storage
        command: ["/bin/sh", "-c"]
        args:
        - |
          /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
        env:
        - name: GROUP_NAME
          value: Lit
        - name: TRACKER_SERVER
          value: "fdfs-tracker.lit.svc:22122"
        volumeMounts:
        - name: fdfs-storage-storage
          mountPath: /var/fdfs
      restartPolicy: Always
      serviceAccountName: default
  volumes:
  - name: fdfs-storage-storage
    emptyDir: {}


# 这里使用了emptyDir作为存储卷,您可能需要根据实际情况替换为Persistent Volumes。
# FDFS-Storage 的 YAML 文件中使用了 env 字段来设置环境变量,其中 TRACKER_SERVER 设置为 fdfs-tracker.lit.svc:22122,这是为了让 Storage 能够找到 Tracker。请确保 Tracker 服务在同一 Kubernetes 集群内,并且服务名正确。

---

apiVersion: v1
kind: Service
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  selector:
    app: fdfs-storage
  ports:
  - protocol: TCP
    port: 23000
    targetPort: 23000
  type: ClusterIP


---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: fdfs-tracker-pv
  namespace: lit
spec:
  storageClassName: alicloud-nas
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: <NAS_SERVER_IP>
    path: </NAS_SERVER_PATH>/fdfs-tracker

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fdfs-tracker-pvc
  namespace: lit
spec:
  storageClassName: alicloud-nas
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-tracker
  template:
    metadata:
      labels:
        app: fdfs-tracker
    spec:
      containers:
      - name: fdfs-tracker
        image: delron/fastdfs:tracker
        command: ["/bin/sh", "-c"]
        args:
        - |
          /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
        volumeMounts:
        - name: fdfs-tracker-storage
          mountPath: /var/fdfs
      restartPolicy: Always
      serviceAccountName: default
  volumes:
  - name: fdfs-tracker-storage
    persistentVolumeClaim:
      claimName: fdfs-tracker-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: fdfs-tracker
  namespace: lit
spec:
  selector:
    app: fdfs-tracker
  ports:
  - protocol: TCP
    port: 22122
    targetPort: 22122
  - protocol: TCP
    port: 23000
    targetPort: 23000
  type: ClusterIP


---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: fdfs-storage-pv
  namespace: lit
spec:
  storageClassName: alicloud-nas
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: <NAS_SERVER_IP>
    path: </NAS_SERVER_PATH>/fdfs-storage

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fdfs-storage-pvc
  namespace: lit
spec:
  storageClassName: alicloud-nas
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fdfs-storage
  template:
    metadata:
      labels:
        app: fdfs-storage
    spec:
      containers:
      - name: fdfs-storage
        image: delron/fastdfs:storage
        command: ["/bin/sh", "-c"]
        args:
        - |
          /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
        env:
        - name: GROUP_NAME
          value: Lit
        - name: TRACKER_SERVER
          value: "fdfs-tracker.lit.svc:22122"
        volumeMounts:
        - name: fdfs-storage-storage
          mountPath: /var/fdfs
      restartPolicy: Always
      serviceAccountName: default
  volumes:
  - name: fdfs-storage-storage
    persistentVolumeClaim:
      claimName: fdfs-storage-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: fdfs-storage
  namespace: lit
spec:
  selector:
    app: fdfs-storage
  ports:
  - protocol: TCP
    port: 23000
    targetPort: 23000
  type: ClusterIP

# 请替换 <NAS_SERVER_IP> 和 <NAS_SERVER_PATH> 为实际的 NAS 服务器 IP 地址和路径。这些 PV 和 PVC 的定义假设您的 NAS 服务器已经设置好,并且 Kubernetes 集群可以访问 NAS 服务器。

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区