专栏首页黑客下午茶Longhorn,企业级云原生容器分布式存储 - K8S 资源配置示例

Longhorn,企业级云原生容器分布式存储 - K8S 资源配置示例

来源于官方 Longhorn 1.1.2 英文技术手册(原创整理)

系列

目录

  • Block volume(块卷示例)
  • CSI persistent volume(CSI 持久卷示例)
  • Deployment(部署示例)
  • Pod with PersistentVolumeClaim(带有持久卷声明的 Pod 示例)
  • Restore to file(恢复到文件示例)
  • Simple Pod(简单 Pod 示例)
  • Simple PersistentVolumeClaim(简单持久卷声明示例)
  • StatefulSet
  • StorageClass

Block Volume(块卷)

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: longhorn-block-vol
    spec:
      accessModes:
        - ReadWriteOnce
      volumeMode: Block
      storageClassName: longhorn
      resources:
        requests:
          storage: 2Gi
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: block-volume-test
      namespace: default
    spec:
      containers:
        - name: block-volume-test
          image: nginx:stable-alpine
          imagePullPolicy: IfNotPresent
          volumeDevices:
            - devicePath: /dev/longhorn/testblk
              name: block-vol
          ports:
            - containerPort: 80
      volumes:
        - name: block-vol
          persistentVolumeClaim:
            claimName: longhorn-block-vol

CSI Persistent Volume(CSI 持久卷)

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: longhorn-vol-pv
    spec:
      capacity:
        storage: 2Gi
      volumeMode: Filesystem
      accessModes:
        - ReadWriteOnce
      persistentVolumeReclaimPolicy: Delete
      storageClassName: longhorn
      csi:
        driver: driver.longhorn.io
        fsType: ext4
        volumeAttributes:
          numberOfReplicas: '3'
          staleReplicaTimeout: '2880'
        volumeHandle: existing-longhorn-volume
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: longhorn-vol-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
      volumeName: longhorn-vol-pv
      storageClassName: longhorn
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: volume-pv-test
      namespace: default
    spec:
      restartPolicy: Always
      containers:
      - name: volume-pv-test
        image: nginx:stable-alpine
        imagePullPolicy: IfNotPresent
        livenessProbe:
          exec:
            command:
              - ls
              - /data/lost+found
          initialDelaySeconds: 5
          periodSeconds: 5
          timeoutSeconds: 4
        volumeMounts:
        - name: vol
          mountPath: /data
        ports:
        - containerPort: 80
      volumes:
      - name: vol
        persistentVolumeClaim:
          claimName: longhorn-vol-pvc

Deployment(部署)

    apiVersion: v1
    kind: Service
    metadata:
      name: mysql
      labels:
        app: mysql
    spec:
      ports:
        - port: 3306
      selector:
        app: mysql
      clusterIP: None
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: mysql-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: longhorn
      resources:
        requests:
          storage: 2Gi
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mysql
      labels:
        app: mysql
    spec:
      selector:
        matchLabels:
          app: mysql # has to match .spec.template.metadata.labels
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: mysql
        spec:
          restartPolicy: Always
          containers:
          - image: mysql:5.6
            name: mysql
            livenessProbe:
              exec:
                command:
                  - ls
                  - /var/lib/mysql/lost+found
              initialDelaySeconds: 5
              periodSeconds: 5
              timeoutSeconds: 4
            env:
            - name: MYSQL_ROOT_PASSWORD
              value: changeme
            ports:
            - containerPort: 3306
              name: mysql
            volumeMounts:
            - name: mysql-volume
              mountPath: /var/lib/mysql
            env:
            - name: MYSQL_ROOT_PASSWORD
              value: "rancher"
          volumes:
          - name: mysql-volume
            persistentVolumeClaim:
              claimName: mysql-pvc

Pod with PersistentVolumeClaim(带有持久卷声明的 Pod)

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: longhorn-volv-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: longhorn
      resources:
        requests:
          storage: 2Gi
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: volume-test
      namespace: default
    spec:
      restartPolicy: Always
      containers:
      - name: volume-test
        image: nginx:stable-alpine
        imagePullPolicy: IfNotPresent
        livenessProbe:
          exec:
            command:
              - ls
              - /data/lost+found
          initialDelaySeconds: 5
          periodSeconds: 5
          timeoutSeconds: 4
        volumeMounts:
        - name: volv
          mountPath: /data
        ports:
        - containerPort: 80
      volumes:
      - name: volv
        persistentVolumeClaim:
          claimName: longhorn-volv-pvc

Restore to file(恢复到文件)

    apiVersion: v1
    kind: Pod
    metadata:
      name: restore-to-file
      namespace: longhorn-system
    spec:
      nodeName: <NODE_NAME>
      containers:
      - name: restore-to-file
        command:
        # set restore-to-file arguments here
        - /bin/sh
        - -c
        - longhorn backup restore-to-file
          '<BACKUP_URL>'
          --output-file '/tmp/restore/<OUTPUT_FILE>'
          --output-format <OUTPUT_FORMAT>
        # the version of longhorn engine should be v0.4.1 or higher
        image: longhorn/longhorn-engine:v0.4.1
        imagePullPolicy: IfNotPresent
        securityContext:
          privileged: true
        volumeMounts:
        - name: disk-directory
          mountPath: /tmp/restore  # the argument <output-file> should be in this directory
        env:
        # set Backup Target Credential Secret here.
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: <S3_SECRET_NAME>
              key: AWS_ACCESS_KEY_ID
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: <S3_SECRET_NAME>
              key: AWS_SECRET_ACCESS_KEY
        - name: AWS_ENDPOINTS
          valueFrom:
            secretKeyRef:
              name: <S3_SECRET_NAME>
              key: AWS_ENDPOINTS
      volumes:
        # the output file can be found on this host path
        - name: disk-directory
          hostPath:
            path: /tmp/restore
      restartPolicy: Never

Simple Pod(简单 Pod)

    apiVersion: v1
    kind: Pod
    metadata:
      name: longhorn-simple-pod
      namespace: default
    spec:
      restartPolicy: Always
      containers:
        - name: volume-test
          image: nginx:stable-alpine
          imagePullPolicy: IfNotPresent
          livenessProbe:
            exec:
              command:
                - ls
                - /data/lost+found
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 4
          volumeMounts:
            - name: volv
              mountPath: /data
          ports:
            - containerPort: 80
      volumes:
        - name: volv
          persistentVolumeClaim:
            claimName: longhorn-simple-pvc

Simple PersistentVolumeClaim(简单持久卷声明)

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: longhorn-simple-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: longhorn
      resources:
        requests:
          storage: 1Gi

StatefulSet

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      ports:
      - port: 80
        name: web
      selector:
        app: nginx
      type: NodePort
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: web
    spec:
      selector:
        matchLabels:
          app: nginx # has to match .spec.template.metadata.labels
      serviceName: "nginx"
      replicas: 2 # by default is 1
      template:
        metadata:
          labels:
            app: nginx # has to match .spec.selector.matchLabels
        spec:
          restartPolicy: Always
          terminationGracePeriodSeconds: 10
          containers:
          - name: nginx
            image: k8s.gcr.io/nginx-slim:0.8
            livenessProbe:
              exec:
                command:
                  - ls
                  - /usr/share/nginx/html/lost+found
              initialDelaySeconds: 5
              periodSeconds: 5
              timeoutSeconds: 4
            ports:
            - containerPort: 80
              name: web
            volumeMounts:
            - name: www
              mountPath: /usr/share/nginx/html
      volumeClaimTemplates:
      - metadata:
          name: www
        spec:
          accessModes: [ "ReadWriteOnce" ]
          storageClassName: "longhorn"
          resources:
            requests:
              storage: 1Gi

StorageClass

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: longhorn
    provisioner: driver.longhorn.io
    allowVolumeExpansion: true
    parameters:
      numberOfReplicas: "3"
      staleReplicaTimeout: "2880" # 48 hours in minutes
      fromBackup: ""
    #  diskSelector: "ssd,fast"
    #  nodeSelector: "storage,fast"
    #  fsType: "ext4"
    #  recurringJobs: '[
    #   {
    #     "name":"snap",
    #     "task":"snapshot",
    #     "cron":"*/1 * * * *",
    #     "retain":1
    #   },
    #   {
    #     "name":"backup",
    #     "task":"backup",
    #     "cron":"*/2 * * * *",
    #     "retain":1,
    #     "labels": {
    #       "interval":"2m"
    #      }
    #   }
    #  ]'

请注意,只有 ext4 文件系统支持在卷意外分离后(detached unexpectedly)自动重新挂载。

本文分享自微信公众号 - 黑客下午茶(hi-weishao),作者:为少

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2021-08-22

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Longhorn,企业级云原生容器分布式存储 - 支持 ReadWriteMany (RWX) 工作负载(实验性功能)

    Longhorn 通过 NFSv4 服务器(share-manager)公开常规 Longhorn 卷,原生支持 RWX 工作负载。

    为少
  • K8s原生存储持续进化,Longhorn 1.1迎来ARM支持

    当DevOps团队同时使用Rancher和Longhorn 1.1时,他们可以轻松管理位于任意位置的持久化数据卷,无论这些持久化数据卷位于云端、数据中心抑或边缘...

    CNCF
  • Longhorn 云原生容器分布式存储 - Python Client

    目前,您可以使用 Longhorn UI 操作 Longhorn。同时,您可以使用 Python 访问 Longhorn API,如下所示。

    为少
  • Longhorn,企业级云原生容器分布式存储 - 监控(Prometheus+AlertManager+Grafana)

    Longhorn 在 REST 端点 http://LONGHORN_MANAGER_IP:PORT/metrics 上以 Prometheus 文本格式原生公...

    为少
  • Longhorn,企业级云原生容器分布式存储 - 高可用

    数据局部性设置(data locality setting)旨在在以下情况下启用:只要有可能,至少应在与使用该卷的 pod 相同的节点上调度 Longhorn ...

    为少
  • Longhorn,企业级云原生容器分布式存储 - 定制部署默认设置

    您可以在部署 Longhorn 时自定义它的默认设置。例如,您可以在启动 Longhorn 之前指定 Create Default Disk With Node...

    为少
  • 使用Longhorn优雅地恢复正在运行中的容器应用

    鞠宏超,Rancher研发工程师。4年云计算领域经验,2018年加入Rancher Labs,先后参与了Longhorn产品研发,Rancher2.x产品研发,...

    CNCF
  • Longhorn云原生容器分布式存储-Air Gap安装

    Longhorn 可以通过使用 manifest file、Helm chart 或 Rancher UI 安装在 air gapped 环境中。

    为少
  • Longhorn 企业级云原生分布式容器存储-券(Volume)和节点(Node)

    在本教程中,您将学习如何创建与 Longhorn 卷对应的持久卷 (PV) 和持久卷声明 (PVC) 的 Kubernetes 持久存储资源。您将使用 kube...

    为少
  • Longhorn,Kubernetes 云原生分布式块存储

    Longhorn 是用于 Kubernetes 的轻量级、可靠且功能强大的分布式块存储系统。

    为少
  • 云原生RDS在k8s中的实现

    沃趣科技作为服务国内B端企业的数据库产品和解决方案的国产厂商,多年与传统企业打交道,深知传统企业目前正面临着互联网应用和数字化全面转型的挑战。我们了解到CIO眼...

    沃趣科技
  • KubeSphere 社区大量全职开源职位诚邀您的加入!

    KubeSphere 团队是开源项目 KubeSphere(https://kubesphere.io)的核心维护成员。在 KubeSphere 团队,一切都是...

    LinuxSuRen
  • sealos+rook 部署 kubeSphere+TiDB

    最近 CNCF 宣布 rook 毕业,kubeSphere 正好也发布了 3.0.0 版本,由于 rancher 开源的 longhorn 还处于孵化阶段,不太...

    米开朗基杨
  • Rancher大中华区技术总监带你6分钟了解Rancher 1.5

    摘要 Rancher容器管理平台1.5版已正式与大家见面了,此次分享将由Rancher Labs大中华区技术总监介绍Rancher的版本演进历史以及Ranche...

    IT大咖说
  • Longhorn 云原生分布式块存储解决方案设计架构和概念

    Longhorn 设计有两层:数据平面(data plane)和控制平面(control plane)。Longhorn Engine 是存储控制器对应数据平面...

    为少
  • 12月容器月报 | 降低 65% 业务成本的弹性容器EKS「竞价实例」上线

    ? 2020年12月 ? ? VOL:08 ? ? ? ? 腾小云告诉你最前线的产品新特性, 总有一款让你心动~ ? 云说新品 ? 容器产品新特性 12月上新...

    腾讯云原生
  • 3月容器产品技术月报|留言抢定制款T恤

    ? 2021年3月 ? ? VOL:11 ? ? ? ? 腾小云告诉你最前线的产品新特性, 总有一款让你心动~ ? 云说新品 ? 容器产品新特性 3月上新 ?...

    腾讯云原生
  • K8S数据保护工具比较

    K8S数据保护工具比较:Cohesity、 Kasten、 OpenEBS、 Portworx、 Rancher Longhorn、 和Velero

    Portworx
  • 附022.Kubernetes_v1.18.3高可用部署架构一

    Kubernetes的高可用主要指的是控制平面的高可用,即指多套Master节点组件和Etcd组件,工作节点通过负载均衡连接到各Master。

    木二

扫码关注云+社区

领取腾讯云代金券