Dra-M Dra-M
首页
技术
冥思
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

莫小龙

保持理智,相信未来。
首页
技术
冥思
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Java基础

  • Spring

  • 微服务

  • Elasticsearch

  • Golang

  • 实用工具

  • Bash

  • DevOps系列

    • 前言:搭建一套自有的围绕K8S的DevOps工具
    • 部署K8S -- kubeasz
    • 部署NFS服务器
    • 为K8S添加StorageClass
    • 学习用NodePort暴露K8S服务
    • 外部nginx代理到nodeport
    • 使用Docker安装LDAP
    • 使用K8S部署LDAP管理面板
    • 使用Docker部署第三方K8S面板Kuboard,并连接LDAP
    • 使用K8S部署GitLab,并连接LDAP
    • 使用K8S部署Jenkins,并连接LDAP
    • 使用K8S部署Nexus,并连接LDAP
    • Nexus Maven私服配置
    • Nexus Docker私服配置+K8S拉取私服镜像
    • Jenkins Pipeline 从 K8s Agent 启动构建
    • Jenkins Pipeline 拉取Git代码 获取提交信息
    • Jenkins Pipeline Maven打包
    • Jenkins Pipeline BuildDockerImage 推送到私服
    • Jenkins Pipeline 部署程序到K8S
    • Jenkins Pipeline 共享库
    • Loki日志收集+K8S
    • SkyWalking链路追踪+K8S、
    • SpringCloud+K8S联调说明
    • DevOps WebHook汇总 (Gitlab,Jenkins,K8S Event)
  • 技术
  • DevOps系列
莫小龙
2022-04-11

为K8S添加StorageClass

SC是K8S的存储声明模板。

在K8S持久化时Pod要与PVC关联,PVC与PV关联。

SC是为了根据PVC自动创建匹配的PV。

sc.png

#RBAC授权
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: devops
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - 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: ["get", "list", "watch", "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: devops
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: devops
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: devops
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: devops
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: devops  #与RBAC文件中的namespace保持一致
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: nfs-storage  #provisioner名称,请确保该名称与 nfs-StorageClass.yaml文件中的provisioner名称保持一致
            - name: NFS_SERVER
              value: 192.168.1.175   #NFS Server IP地址
            - name: NFS_PATH  
              value: /home/public/k8sdata    #NFS挂载卷
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.1.175  #NFS Server IP地址
            path: /home/public/k8sdata     #NFS 挂载卷
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: nfs-storage #这里的名称要和provisioner配置文件中的环境变量PROVISIONER_NAME保持一致
parameters:
  archiveOnDelete: "ture"  
  reclaimPolicy: Retain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

#DevOps#K8S#运维
上次更新: 4/11/2022
部署NFS服务器
学习用NodePort暴露K8S服务

← 部署NFS服务器 学习用NodePort暴露K8S服务→

最近更新
01
【代码片段】我使用的Gin中间处理器(自定义异常处理、日志打印、traceId、跨域配置)
12-03
02
【Java转Go】如何理解Go中的值类型、引用类型、nil
12-03
03
【Java转Go】如何理解面向对象,怎么把Golang用成面向对象的样子
12-02
更多文章>
Theme by Vdoing | Copyright © 2019-2023 Dra-M | 冀ICP备2021002204号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式