个人随笔
目录
Kubernetes上安装KubeSphere教程
2023-02-24 12:59:07

该篇集群搭建是在我前两篇博文的基础上搭建的

k8s集群环境搭建
k8s实战 这里主要是装好了NFS

参考官方文档,在Kubernetes上安装:https://kubesphere.io/zh/docs/v3.3/installing-on-kubernetes/introduction/overview/

一、环境准备

1、k8s版本

1-1、官网上说如需在 Kubernetes 上安装 KubeSphere 3.3,您的 Kubernetes 版本必须为:v1.19.x、v1.20.x、v1.21.x、 v1.22.x、 v1.23.x 和 * v1.24.x。带星号的版本可能出现边缘节点部分功能不可用的情况。因此,如需使用边缘节点,推荐安装 v1.21.x 及之前的版本。

我们先看一下自己的版本

  1. [root@k8s-new-master ~]# kubectl version
  2. Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.9", GitCommit:"7a576bc3935a6b555e33346fd73ad77c925e9e4a", GitTreeState:"clean", BuildDate:"2021-07-15T21:01:38Z", GoVersion:"go1.15.14", Compiler:"gc", Platform:"linux/amd64"}
  3. Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.9", GitCommit:"7a576bc3935a6b555e33346fd73ad77c925e9e4a", GitTreeState:"clean", BuildDate:"2021-07-15T20:56:38Z", GoVersion:"go1.15.14", Compiler:"gc", Platform:"linux/amd64"}

1.20.9是符合上面描述的版本的。

1-2、可用 CPU > 1 核;内存 > 2 G。CPU 必须为 x86_64,暂时不支持 Arm 架构的 CPU。
我的虚拟机配置是2核4G也是符合要求的

1-3、Kubernetes 集群已配置默认 StorageClass(请使用 kubectl get sc 进行确认)。

  1. [root@k8s-new-master ~]# kubectl get sc
  2. No resources found

这个是空的,不符合要求,得先装一下。
直接准备好yaml,用kubectl命令安装即可

  1. ## 创建了一个存储类
  2. apiVersion: storage.k8s.io/v1
  3. kind: StorageClass
  4. metadata:
  5. name: nfs-storage
  6. annotations:
  7. storageclass.kubernetes.io/is-default-class: "true"
  8. provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
  9. parameters:
  10. archiveOnDelete: "true" ## 删除pv的时候,pv的内容是否要备份
  11. ---
  12. apiVersion: apps/v1
  13. kind: Deployment
  14. metadata:
  15. name: nfs-client-provisioner
  16. labels:
  17. app: nfs-client-provisioner
  18. # replace with namespace where provisioner is deployed
  19. namespace: default
  20. spec:
  21. replicas: 1
  22. strategy:
  23. type: Recreate
  24. selector:
  25. matchLabels:
  26. app: nfs-client-provisioner
  27. template:
  28. metadata:
  29. labels:
  30. app: nfs-client-provisioner
  31. spec:
  32. serviceAccountName: nfs-client-provisioner
  33. containers:
  34. - name: nfs-client-provisioner
  35. image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
  36. # resources:
  37. # limits:
  38. # cpu: 10m
  39. # requests:
  40. # cpu: 10m
  41. volumeMounts:
  42. - name: nfs-client-root
  43. mountPath: /persistentvolumes
  44. env:
  45. - name: PROVISIONER_NAME
  46. value: k8s-sigs.io/nfs-subdir-external-provisioner
  47. - name: NFS_SERVER
  48. value: 192.168.192.8 ## 指定自己nfs服务器地址
  49. - name: NFS_PATH
  50. value: /nfs/data ## nfs服务器共享的目录
  51. volumes:
  52. - name: nfs-client-root
  53. nfs:
  54. server: 192.168.192.8 ## 指定自己nfs服务器地址
  55. path: /nfs/data
  56. ---
  57. apiVersion: v1
  58. kind: ServiceAccount
  59. metadata:
  60. name: nfs-client-provisioner
  61. # replace with namespace where provisioner is deployed
  62. namespace: default
  63. ---
  64. kind: ClusterRole
  65. apiVersion: rbac.authorization.k8s.io/v1
  66. metadata:
  67. name: nfs-client-provisioner-runner
  68. rules:
  69. - apiGroups: [""]
  70. resources: ["nodes"]
  71. verbs: ["get", "list", "watch"]
  72. - apiGroups: [""]
  73. resources: ["persistentvolumes"]
  74. verbs: ["get", "list", "watch", "create", "delete"]
  75. - apiGroups: [""]
  76. resources: ["persistentvolumeclaims"]
  77. verbs: ["get", "list", "watch", "update"]
  78. - apiGroups: ["storage.k8s.io"]
  79. resources: ["storageclasses"]
  80. verbs: ["get", "list", "watch"]
  81. - apiGroups: [""]
  82. resources: ["events"]
  83. verbs: ["create", "update", "patch"]
  84. ---
  85. kind: ClusterRoleBinding
  86. apiVersion: rbac.authorization.k8s.io/v1
  87. metadata:
  88. name: run-nfs-client-provisioner
  89. subjects:
  90. - kind: ServiceAccount
  91. name: nfs-client-provisioner
  92. # replace with namespace where provisioner is deployed
  93. namespace: default
  94. roleRef:
  95. kind: ClusterRole
  96. name: nfs-client-provisioner-runner
  97. apiGroup: rbac.authorization.k8s.io
  98. ---
  99. kind: Role
  100. apiVersion: rbac.authorization.k8s.io/v1
  101. metadata:
  102. name: leader-locking-nfs-client-provisioner
  103. # replace with namespace where provisioner is deployed
  104. namespace: default
  105. rules:
  106. - apiGroups: [""]
  107. resources: ["endpoints"]
  108. verbs: ["get", "list", "watch", "create", "update", "patch"]
  109. ---
  110. kind: RoleBinding
  111. apiVersion: rbac.authorization.k8s.io/v1
  112. metadata:
  113. name: leader-locking-nfs-client-provisioner
  114. # replace with namespace where provisioner is deployed
  115. namespace: default
  116. subjects:
  117. - kind: ServiceAccount
  118. name: nfs-client-provisioner
  119. # replace with namespace where provisioner is deployed
  120. namespace: default
  121. roleRef:
  122. kind: Role
  123. name: leader-locking-nfs-client-provisioner
  124. apiGroup: rbac.authorization.k8s.io

执行

  1. kubectl apply -f sc.yaml

再查看

  1. root@k8s-new-master ~]# kubectl get sc
  2. NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
  3. nfs-storage (default) k8s-sigs.io/nfs-subdir-external-provisioner Delete Immediate false 30s
  4. [root@k8s-new-master ~]#

目前也已经有了,可以进行搭建了。

我们这里最好再安装一个集群监控指标组件

2、metrics-server

集群指标监控组件

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. labels:
  5. k8s-app: metrics-server
  6. name: metrics-server
  7. namespace: kube-system
  8. ---
  9. apiVersion: rbac.authorization.k8s.io/v1
  10. kind: ClusterRole
  11. metadata:
  12. labels:
  13. k8s-app: metrics-server
  14. rbac.authorization.k8s.io/aggregate-to-admin: "true"
  15. rbac.authorization.k8s.io/aggregate-to-edit: "true"
  16. rbac.authorization.k8s.io/aggregate-to-view: "true"
  17. name: system:aggregated-metrics-reader
  18. rules:
  19. - apiGroups:
  20. - metrics.k8s.io
  21. resources:
  22. - pods
  23. - nodes
  24. verbs:
  25. - get
  26. - list
  27. - watch
  28. ---
  29. apiVersion: rbac.authorization.k8s.io/v1
  30. kind: ClusterRole
  31. metadata:
  32. labels:
  33. k8s-app: metrics-server
  34. name: system:metrics-server
  35. rules:
  36. - apiGroups:
  37. - ""
  38. resources:
  39. - pods
  40. - nodes
  41. - nodes/stats
  42. - namespaces
  43. - configmaps
  44. verbs:
  45. - get
  46. - list
  47. - watch
  48. ---
  49. apiVersion: rbac.authorization.k8s.io/v1
  50. kind: RoleBinding
  51. metadata:
  52. labels:
  53. k8s-app: metrics-server
  54. name: metrics-server-auth-reader
  55. namespace: kube-system
  56. roleRef:
  57. apiGroup: rbac.authorization.k8s.io
  58. kind: Role
  59. name: extension-apiserver-authentication-reader
  60. subjects:
  61. - kind: ServiceAccount
  62. name: metrics-server
  63. namespace: kube-system
  64. ---
  65. apiVersion: rbac.authorization.k8s.io/v1
  66. kind: ClusterRoleBinding
  67. metadata:
  68. labels:
  69. k8s-app: metrics-server
  70. name: metrics-server:system:auth-delegator
  71. roleRef:
  72. apiGroup: rbac.authorization.k8s.io
  73. kind: ClusterRole
  74. name: system:auth-delegator
  75. subjects:
  76. - kind: ServiceAccount
  77. name: metrics-server
  78. namespace: kube-system
  79. ---
  80. apiVersion: rbac.authorization.k8s.io/v1
  81. kind: ClusterRoleBinding
  82. metadata:
  83. labels:
  84. k8s-app: metrics-server
  85. name: system:metrics-server
  86. roleRef:
  87. apiGroup: rbac.authorization.k8s.io
  88. kind: ClusterRole
  89. name: system:metrics-server
  90. subjects:
  91. - kind: ServiceAccount
  92. name: metrics-server
  93. namespace: kube-system
  94. ---
  95. apiVersion: v1
  96. kind: Service
  97. metadata:
  98. labels:
  99. k8s-app: metrics-server
  100. name: metrics-server
  101. namespace: kube-system
  102. spec:
  103. ports:
  104. - name: https
  105. port: 443
  106. protocol: TCP
  107. targetPort: https
  108. selector:
  109. k8s-app: metrics-server
  110. ---
  111. apiVersion: apps/v1
  112. kind: Deployment
  113. metadata:
  114. labels:
  115. k8s-app: metrics-server
  116. name: metrics-server
  117. namespace: kube-system
  118. spec:
  119. selector:
  120. matchLabels:
  121. k8s-app: metrics-server
  122. strategy:
  123. rollingUpdate:
  124. maxUnavailable: 0
  125. template:
  126. metadata:
  127. labels:
  128. k8s-app: metrics-server
  129. spec:
  130. containers:
  131. - args:
  132. - --cert-dir=/tmp
  133. - --kubelet-insecure-tls
  134. - --secure-port=4443
  135. - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
  136. - --kubelet-use-node-status-port
  137. image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/metrics-server:v0.4.3
  138. imagePullPolicy: IfNotPresent
  139. livenessProbe:
  140. failureThreshold: 3
  141. httpGet:
  142. path: /livez
  143. port: https
  144. scheme: HTTPS
  145. periodSeconds: 10
  146. name: metrics-server
  147. ports:
  148. - containerPort: 4443
  149. name: https
  150. protocol: TCP
  151. readinessProbe:
  152. failureThreshold: 3
  153. httpGet:
  154. path: /readyz
  155. port: https
  156. scheme: HTTPS
  157. periodSeconds: 10
  158. securityContext:
  159. readOnlyRootFilesystem: true
  160. runAsNonRoot: true
  161. runAsUser: 1000
  162. volumeMounts:
  163. - mountPath: /tmp
  164. name: tmp-dir
  165. nodeSelector:
  166. kubernetes.io/os: linux
  167. priorityClassName: system-cluster-critical
  168. serviceAccountName: metrics-server
  169. volumes:
  170. - emptyDir: {}
  171. name: tmp-dir
  172. ---
  173. apiVersion: apiregistration.k8s.io/v1
  174. kind: APIService
  175. metadata:
  176. labels:
  177. k8s-app: metrics-server
  178. name: v1beta1.metrics.k8s.io
  179. spec:
  180. group: metrics.k8s.io
  181. groupPriorityMinimum: 100
  182. insecureSkipTLSVerify: true
  183. service:
  184. name: metrics-server
  185. namespace: kube-system
  186. version: v1beta1
  187. versionPriority: 100

二、安装KubeSphere

1、下载核心文件

  1. wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
  2. wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml

如果下载不到,请用下面的地址

  1. wget https://www.suibibk.com//fileupload/files/kubesphere-installer.yaml
  2. wget https://www.suibibk.com//fileupload/files/cluster-configuration.yaml

2、修改cluster-configuration

在 cluster-configuration.yaml中指定我们需要开启的功能
参照官网“启用可插拔组件”
https://kubesphere.io/zh/docs/v3.3/pluggable-components/

3、执行安装

  1. kubectl apply -f kubesphere-installer.yaml
  2. kubectl apply -f cluster-configuration.yaml

4、查看安装进度

  1. kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

要过一会才能查看到进度

  1. **************************************************
  2. Waiting for all tasks to be completed ...
  3. task network status is successful (1/11)
  4. task alerting status is successful (2/11)
  5. task multicluster status is successful (3/11)
  6. task openpitrix status is successful (4/11)
  7. task auditing status is successful (5/11)
  8. task logging status is successful (6/11)
  9. task events status is successful (7/11)
  10. task kubeedge status is successful (8/11)
  11. task devops status is successful (9/11)
  12. task monitoring status is successful (10/11)
  13. ...

貌似要等挺久的呢,等待中…

  1. **************************************************
  2. Collecting installation results ...
  3. #####################################################
  4. ### Welcome to KubeSphere! ###
  5. #####################################################
  6. Console: http://192.168.192.8:30880
  7. Account: admin
  8. Password: P@88w0rd

我能说等了差不多一个钟么,我以为坏掉了呢!可能是我的本地配置太垃圾了,尝试访问下。

5、访问登录

登录后,我把密码改为了:Abc123

也就是后面实战的登录为

  1. Console: http://192.168.192.8:30880
  2. Account: admin
  3. Password: Abc123

参考
1、视频教程
https://www.bilibili.com/video/BV13Q4y1C7hS
2、笔记
https://www.yuque.com/leifengyang/oncloud/

 551

啊!这个可能是世界上最丑的留言输入框功能~


当然,也是最丑的留言列表

有疑问发邮件到 : suibibk@qq.com 侵权立删
Copyright : 个人随笔   备案号 : 粤ICP备18099399号-2