一、首先配置pv自动供给。这里以nfs为准。

在nfs主机上安装nfs

yum -y install nfs-utils.x86_64

并且配置对应配置文件

[root@k8s-node2 yum.repos.d]# cat /etc/exports
/pvshare/sa *(rw,sync,no_root_squash)

启动nfs,并设置为开机自启动

systemctl start nfs

systemctl enable nfs   #开机自启动

完成之后可以在对应远程主机上面mount安装试一下,确保是ok的。

二、在k8s上面配置pv的自动供给。

[root@k8s-master1 StorageClass]# cat nfs-client.yaml
apiVersion: apps/v1
kind: Deployment
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: quay.io/external_storage/nfs-client-provisioner:latest
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: 192.168.10.13
- name: NFS_PATH
value: /pvshare/sa
volumes:
- name: nfs-client-root
nfs:
server: 192.168.10.13
path: /pvshare/sa

 

 镜像可能拉取比较困难,所以我一般先手动拉取下来先。

[root@k8s-master1 StorageClass]# cat nfs-client-sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner

---
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: ["list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io

 

 

创建对应的StorageClass

[root@k8s-master1 StorageClass]# cat nfs-client-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: course-nfs-storage
provisioner: fuseim.pri/ifs

 

 

应用这些配置:只要nfs没问题,基本都是ok。

kubectl apply -f nfs-client.yaml

kubectl apply -f nfs-client-sa.yaml

kubectl apply -f nfs-client-class.yaml

通过kubectl get storageclass

 

 三、配置kubesphere

1、先应用这个:kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/kubesphere-installer.yaml

2、再应用这个:kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/cluster-configuration.yaml

不过基本起不来,所以自己搞定镜像的问题吧。可以先拉下来,放到自己的镜像仓库。再运行。第二步要记得更换storageclass的名称,默认是defaults。不生效。一定要换,不然自己建一个defaults的storagessclass。

3、查看安装日志 (其实不看日志也行,只要所有pod都是running状态就行,如果网络慢,可能就慢点。)

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

4、查看对应三个命名空间下面的pod和svc,确保都启动完成。

 

 

 

 

 

 

 

 5、登陆kubesphere
ip:30880
用户名:admin
默认密码:P@88w0rd

 

 

至此,正常使用即可。