首页 > 其他分享 >Kubernetes 硬盘持久化之 StorageClass

Kubernetes 硬盘持久化之 StorageClass

时间:2024-05-30 19:33:26浏览次数:17  
标签:kind name Kubernetes client nfs StorageClass io provisioner 硬盘

Kubernetes 硬盘持久化之 StorageClass

StorageClass 定义

StorageClass 为管理员提供了描述存储"类"的方法。 不同的类型可能会映射到不同的服务质量等级或备份策略,或是由集群管理员制定的任意策略。 这个类的概念在其他存储系统中有时被称为"配置文件"。每个 StorageClass 都包含 provisionerparametersreclaimPolicy 字段, 这些字段会在 StorageClass 需要动态制备 PersistentVolume 时会使用到。

StorageClass 使用

  1. 创建 NFS 制备商账户 nfs-client-provisionerrabc.yaml权限文件

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: nfs-client-provisioner
      # replace with namespace where provisioner is deployed
      namespace: default
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: nfs-client-provisioner-runner
    rules:
      - apiGroups: [""]
        resources: ["nodes"]
        verbs: ["get", "list", "watch"]
      - apiGroups: [""]
        resources: ["persistentvolumes"]
        verbs: ["get", "list", "watch", "create", "delete"]
      - apiGroups: [""]
        resources: ["persistentvolumeclaims"]
        verbs: ["get", "list", "watch", "update"]
      - apiGroups: ["storage.k8s.io"]
        resources: ["storageclasses"]
        verbs: ["get", "list", "watch"]
      - apiGroups: [""]
        resources: ["events"]
        verbs: ["create", "update", "patch"]
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: run-nfs-client-provisioner
    subjects:
      - kind: ServiceAccount
        name: nfs-client-provisioner
        # replace with namespace where provisioner is deployed
        namespace: default
    roleRef:
      kind: ClusterRole
      name: nfs-client-provisioner-runner
      apiGroup: rbac.authorization.k8s.io
    ---
    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: leader-locking-nfs-client-provisioner
      # replace with namespace where provisioner is deployed
      namespace: default
    rules:
      - apiGroups: [""]
        resources: ["endpoints"]
        verbs: ["get", "list", "watch", "create", "update", "patch"]
    ---
    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: leader-locking-nfs-client-provisioner
      # replace with namespace where provisioner is deployed
      namespace: default
    subjects:
      - kind: ServiceAccount
        name: nfs-client-provisioner
        # replace with namespace where provisioner is deployed
        namespace: default
    roleRef:
      kind: Role
      name: leader-locking-nfs-client-provisioner
      apiGroup: rbac.authorization.k8s.io
    
    root@k8s-master1:~# kubectl get sa
    NAME                     SECRETS   AGE
    default                  0         15d
    nfs-client-provisioner   0         5s
    
  2. 创建 NFS 制备商 Pod

    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: nfs-client-provisioner
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nfs-client-provisioner
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: nfs-client-provisioner
        spec:
          serviceAccountName: nfs-client-provisioner
          containers:
            - name: nfs-client-provisioner
              image: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
              volumeMounts:
                - name: nfs-client-root
                  mountPath: /persistentvolumes
              env:
                - name: PROVISIONER_NAME
                  value: k8s-sigs.io/nfs-subdir-external-provisioner
                - name: NFS_SERVER
                  value: 192.168.31.60
                - name: NFS_PATH
                  value: /nfs-test
          volumes:
            - name: nfs-client-root
              nfs:
                server: 192.168.31.60
                path: /nfs-test
    
  3. 创建 NFS StorageClass

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: nfs-client
    provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
    parameters:
      pathPattern: "${.PVC.namespace}/${.PVC.annotations.nfs.io/storage-path}" # waits for nfs.io/storage-path annotation, if not specified will accept as empty string.
      onDelete: delete
    
  4. 创建 NFS PVC

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: nfs-claim1
      annotations:
        nfs.io/storage-path: "pvc1"
    spec:
      storageClassName: nfs-client
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 100Mi
    ---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: nfs-claim2
      annotations:
        nfs.io/storage-path: "pvc2"
    spec:
      storageClassName: nfs-client
      accessModes:
        - ReadOnlyMany
      resources:
        requests:
          storage: 100Mi
    
  5. 创建测试 Pod

    kind: Pod
    apiVersion: v1
    metadata:
      name: pod-nfs-test1
    spec:
      containers:
        - name: nfs-test1
          image: busybox:stable
          command:
            - "/bin/sh"
          args:
            - "-c"
            - "echo hello > /mnt/SUCCESS1 && exit 0 || exit 1"
          volumeMounts:
            - name: nfs-pvc1
              mountPath: "/mnt"
      restartPolicy: "Never"
      volumes:
        - name: nfs-pvc1
          persistentVolumeClaim:
            claimName: nfs-claim1
    ---
    kind: Pod
    apiVersion: v1
    metadata:
      name: pod-nfs-test2
    spec:
      containers:
        - name: nfs-test2
          image: busybox:stable
          command:
            - "/bin/sh"
          args:
            - "-c"
            - "echo hello > /mnt/SUCCESS2 && exit 0 || exit 1"
          volumeMounts:
            - name: nfs-pvc2
              mountPath: "/mnt"
      restartPolicy: "Never"
      volumes:
        - name: nfs-pvc2
          persistentVolumeClaim:
            claimName: nfs-claim2
    

标签:kind,name,Kubernetes,client,nfs,StorageClass,io,provisioner,硬盘
From: https://blog.csdn.net/baidu_34688878/article/details/139286925

相关文章

  • 在kubernetes里使用seccomp限制容器的系统调用
    目录一.系统环境二.前言三.系统调用简介四.使用seccomp限制docker容器系统调用五.在kubernetes里使用seccomp限制容器的系统调用5.1配置seccomp允许pod进行所有系统调用5.2配置seccomp禁止pod进行所有系统调用5.3配置seccomp允许pod进行50个系统调用六.总结一.系统环境本文主......
  • 12.1 SAS-SATA-SSD-SCSI-IDE 硬盘讲解
    12.1.1常见磁盘类型:1.SAS硬盘:1.1SAS(串行链接SCSI接口)1.2SAS(SerialAttachedSCSI),串行连接SCSI接口,串行连接小型计算机系统接口。1.3SAS是新一代的SCSI技术,和现在流行的SerialATA(SATA)因公安相同,都是采用串行技术以获......
  • 三、(1)Kubernetes基本概念和术语
    目录1.1资源对象概述1.2集群类1.3应用类1. serviceandpod:应用类相关的资源对象主要是围绕service和pod来进行说明的。2.Lable与标签选择器3.pod与deployment4.service的clusterIP地址5.service的外网访问问题6.有状态的应用集群7.与应用运维相关对象考虑......
  • filebeat配置参数add_kubernetes_metadata
    在Kubernetes集群中,我们可以使用Filebeat来从容器中收集日志,并为每个日志事件添加Kubernetes相关的元数据信息,例如Pod名称、命名空间、标签等。这样我们就可以更好地分析和理解日志数据。filebeat.inputs:-type:containerpaths:-/var/log/containers/*.log......
  • 在kubernetes里使用AppArmor限制容器对资源的访问
    目录一.系统环境二.前言三.AppArmor简介四.AppArmor和SELinux的区别五.使用AppArmor限制nginx程序访问目录5.1安装nginx5.2修改nginx的默认主页5.3安装AppArmor实用工具5.4AppArmor规则解释5.5配置AppArmor规则限制nginx程序访问目录六.在kubernetes里使用AppArmor限制容器对......
  • 原生ceph更换故障硬盘过程
    准备1、确定故障硬盘所在节点的信息,避免操作错误 2确定故障osd的lvm信息 ceph-c8fd9380-1a1a-45e4-a43a-b36da6fdc560ceph-22b06ce3-0186-40cf-9095-e777bc458bf63确认数据盘对应的缓存盘(查看ceph部署时的日志)osd.9->sdb2 osd.81->sdc6更换步骤1禁止平台数......
  • 自动化测试在 Kubernetes Operator 开发中的应用:以 OpenTelemetry 为例
    背景最近在给opentelemetry-operator提交一个标签选择器的功能时,因为当时修改的函数是私有的,无法添加单测函数,所以社区建议我补充一个e2etest.因为在当前的版本下,只要给deployment打上了instrumentation.opentelemetry.io/inject-java:"true"这类注解就会给该deployme......
  • Kubernetes(k8s) v1.30.1 本地集群部署 安装metallb 支持LoadBalancer 生产环境 推荐
    1 metallb安装参考:Kubernetes(k8s)v1.30.1本地集群部署默认不支持LoadBalancermetallb来解决-CSDN博客2 删除Layer2模式配置kubectldelete-fIPAddressPool.yamlkubectldelete-fL2Advertisement.yamlkubectldelete-fdiscuz-srv.yaml3配置k8sMeta......
  • Kubernetes中Pod容器的资源限制和探针配置
    前言在Kubernetes中,定义Pod时可以选择性地为每个容器设定所需要的资源数量。最常见的可设定资源是CPU和内存大小,以及其他类型的资源;另一方面,通过配置探针,可以确保容器在运行时保持健康,并且只有在准备好接收流量时才会被负载均衡器引导流量。从而提高应用程序的可靠性和......
  • 创新实训2024.05.26日志:落地基于硬盘的数据库服务
    1.需求任务列表以下描述易学大模型软件的web应用的功能。用户注册用户邮箱,密码,验证码开启官方邮箱,用来发验证码(QQ网易都支持开启smtp协议,找教程,用邮箱不用手机号是为了省买发短信云服务的钱)验证码缓存于redis,5min内有效验证密码长度,验证码是否正确新用户信息保存于mysq......