赞
踩
KubeSphere
是在 Kubernetes
之上构建的面向云原生应用的分布式操作系统,完全开源,支持多云与多集群管理,提供全栈的 IT 自动化运维能力,简化企业的DevOps
工作流,它的架构可以非常方便地使第三方应用与云原生生态组件进行即插即用 (plug-and-play) 的集成。KubeSphere
提供了运维友好的向导式操作界面,帮助企业快速构建一个强大和功能丰富的容器云平台。KubeSphere
为用户提供构建企业级 Kubernetes 环境所需的多项功能,例如多云与多集群管理、**Kubernetes**
** 资源管理、DevOps、应用生命周期管理、微服务治理(服务网格)、日志查询与收集、服务与网络、多租户管理、监控告警、事件与审计查询、存储管理、访问权限控制、GPU 支持、网络策略、镜像仓库管理以及安全管理**等。KubeSphere
还开源了 KubeKey 帮助企业一键在公有云或数据中心快速搭建 Kubernetes 集群,提供单节点、多节点、集群插件安装,以及集群升级与运维。KubeSphere
,并同时配置Kubernetes
。另外,只要Kubernetes
集群满足以下前提条件,那么您也可以在云托管和本地Kubernetes
集群上部署 KubeSphere
。Kubernetes
上安装 KubeSphere v3.1.1
,您的 Kubernetes 版本必须为:v1.17.x,v1.18.x,v1.19.x 或 v1.20.x。Kubernetes
集群环境,最少一个master
节点和工作节点,master
节点已经初始化,工作节点已经加入到master
节点。yum install -y nfs-utils
Node1
主节点NFS网络文件配置。# nfs主节点
mkdir -p /nfs/data
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 设置开机自启 & 现在启动 -- 远程绑定服务
systemctl enable rpcbind --now
# nfs服务
systemctl enable nfs-server --now
# 配置生效
exportfs -r
# 查看
exportfs
Node1
主节点基础环境。Node2
从节点NFS网络文件配置。# 查看远程机器有哪些目录可以同步 --使用master机器ip地址
showmount -e 192.168.47.139
# 执行以下命令挂载 nfs 服务器上的共享目录到本机路径
mkdir -p /nfs/data
# 同步远程机器数据
mount -t nfs 192.168.47.139:/nfs/data /nfs/data
Node3
从节点NFS网络文件配置。# 查看远程机器有哪些目录可以同步 --使用master机器ip地址
showmount -e 192.168.47.139
# 执行以下命令挂载 nfs 服务器上的共享目录到本机路径
mkdir -p /nfs/data
# 同步远程机器数据
mount -t nfs 192.168.47.139:/nfs/data /nfs/data
# 在任意机器写入一个测试文件
echo "hello nfs" > /nfs/data/test.txt
# 在其它机器查看数据
cat /nfs/data/test.txt
该操作只需要在Node1
主节点上操作即可
storageclass.yaml
文件的配置。
spec>env>value
和volumes>server
换成你自己主节点上的IP地址。## 创建了一个存储类 apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: nfs-storage annotations: storageclass.kubernetes.io/is-default-class: "true" provisioner: k8s-sigs.io/nfs-subdir-external-provisioner parameters: archiveOnDelete: "true" ## 删除pv的时候,pv的内容是否要备份 --- apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default spec: replicas: 1 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: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2 # resources: # limits: # cpu: 10m # requests: # cpu: 10m 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.47.139 ## 指定自己nfs服务器地址 - name: NFS_PATH value: /nfs/data ## nfs服务器共享的目录 volumes: - name: nfs-client-root nfs: server: 192.168.47.139 ##nfs服务器共享的目录 path: /nfs/data --- 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
storageclass.yaml
文件。kubectl apply -f storageclass.yaml
kubectl get sc
NFS-Client
Pod状态kubectl get pods -A
该操作只需要在Node1
主节点上操作即可
默认是没有监控节点和POD的组件。
Metrics-Server
:它是集群指标监控组件,用于和API Server交互,获取(采集)Kubernetes集群中各项指标数据的。有了它我们可以查看各个Pod,Node等其他资源的CPU,Mem(内存)使用情况。
KubeSphere
:可以充当Kubernetes的dashboard(可视化面板)因此KubeSphere要想获取Kubernetes的各项数据,就需要某个组件去提供给想数据,这个数据采集功能由Metrics-Server实现。
Metrics-Server
监控服务。
metrics-server.yaml
的文件apiVersion: v1 kind: ServiceAccount metadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: k8s-app: metrics-server rbac.authorization.k8s.io/aggregate-to-admin: "true" rbac.authorization.k8s.io/aggregate-to-edit: "true" rbac.authorization.k8s.io/aggregate-to-view: "true" name: system:aggregated-metrics-reader rules: - apiGroups: - metrics.k8s.io resources: - pods - nodes verbs: - get - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: k8s-app: metrics-server name: system:metrics-server rules: - apiGroups: - "" resources: - pods - nodes - nodes/stats - namespaces - configmaps verbs: - get - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: labels: k8s-app: metrics-server name: metrics-server-auth-reader namespace: kube-system roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: extension-apiserver-authentication-reader subjects: - kind: ServiceAccount name: metrics-server namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: k8s-app: metrics-server name: metrics-server:system:auth-delegator roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:auth-delegator subjects: - kind: ServiceAccount name: metrics-server namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: k8s-app: metrics-server name: system:metrics-server roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:metrics-server subjects: - kind: ServiceAccount name: metrics-server namespace: kube-system --- apiVersion: v1 kind: Service metadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-system spec: ports: - name: https port: 443 protocol: TCP targetPort: https selector: k8s-app: metrics-server --- apiVersion: apps/v1 kind: Deployment metadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-system spec: selector: matchLabels: k8s-app: metrics-server strategy: rollingUpdate: maxUnavailable: 0 template: metadata: labels: k8s-app: metrics-server spec: containers: - args: - --cert-dir=/tmp - --kubelet-insecure-tls - --secure-port=4443 - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname - --kubelet-use-node-status-port image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/metrics-server:v0.4.3 imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 3 httpGet: path: livez port: https scheme: HTTPS periodSeconds: 10 name: metrics-server ports: - containerPort: 4443 name: https protocol: TCP readinessProbe: failureThreshold: 3 httpGet: path: readyz port: https scheme: HTTPS periodSeconds: 10 securityContext: readOnlyRootFilesystem: true runAsNonRoot: true runAsUser: 1000 volumeMounts: - mountPath: tmp name: tmp-dir nodeSelector: kubernetes.io/os: linux priorityClassName: system-cluster-critical serviceAccountName: metrics-server volumes: - emptyDir: {} name: tmp-dir --- apiVersion: apiregistration.k8s.io/v1 kind: APIService metadata: labels: k8s-app: metrics-server name: v1beta1.metrics.k8s.io spec: group: metrics.k8s.io groupPriorityMinimum: 100 insecureSkipTLSVerify: true service: name: metrics-server namespace: kube-system version: v1beta1 versionPriority: 100
manifests
文件夹修改kube-apiserver.yaml
--enable-aggregator-routing=true
spec:
containers:
- command:
- kube-apiserver
- --advertise-address=192.168.47.139
- --allow-privileged=true
- --authorization-mode=Node,RBAC
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --enable-admission-plugins=NodeRestriction
- --enable-bootstrap-token-auth=true
- --enable-aggregator-routing=true
kubelet
服务systemctl daemon-reload
systemctl restart kubelet
docker
拉取Metrics-Server
监控服务镜像docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.4.3
metrics-server.yaml
的文件kubectl apply -f metrics-server.yaml
metrics-server
状态kubectl get pods -n kube-system
metrics-server
监控组件#验证K8s节点
kubectl top nodes
#验证Pod
kubectl top pods -A
至此Kubesphere基本环境和默认存储PVC搭建完成
Kubesphere
环境Yaml
文件#创建目录
mkdir /usr/local/sbin/kubesphere
#进入文件目录
cd /usr/local/sbin/kubesphere
#拉取Yaml配置文件
wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml
cluster-configuration.yaml
文件的可插拔组件
kubectl apply -f kubesphere-installer.yaml
kubectl apply -f cluster-configuration.yaml
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
http://192.168.47.139:30880
admin
P@88w0rd
Kubesphere
环境搭建完成Kubesphere
开启对DevOps
组件的支持。KubeSphere Web
控制台查看和操作不同的资源。要在安装后启用可插拔组件,只需要在控制台中进行略微调整。对于那些习惯使用 Kubernetes
命令行工具 kubectl
的人来说,由于该工具已集成到控制台中,因此使用KubeSphere
将毫无困难。admin
身份登录控制台。点击左上角的平台管理 ,然后选择集群管理。clusterconfiguration
,点击搜索结果进入其详情页面。clusterconfiguration
进入资源列表,进行编辑配置文件。Devops
组件的环境支持
enable:false
改为enable:true
,点击更新即可kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
Pod
调度异常,只能在分配到的节点上手动拉取下镜像,可以看到已经有Devops
了。
kubesphere3.1.x
文档:https://v3-1.docs.kubesphere.io/zh/docs/quick-start/create-workspace-and-project/kubesphere3.1.x
文档:https://v3-1.docs.kubesphere.io/zh/docs/quick-start/wordpress-deployment/Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。