各节点升级内核(CephFS需要内核在4.10以上)

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml -y
grub2-set-default 0
init 6

添加证书

#查看证书秘钥
kubectl create secret generic cephfs-secret --type="kubernetes.io/cephfs" \
--from-literal=key=$(ceph auth print-key client.admin) \
--namespace=kube-system
kubectl create secret generic cephfs-secret --type="kubernetes.io/cephfs" \
> --from-literal=key=$(ceph auth print-key client.admin) \
> --namespace=default

添加PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: cephfs-pv3
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  cephfs:
    monitors:
      - 192.168.1.111:6789,192.168.1.112:6789,192.168.1.113:6789
    path: /
    user: admin
    secretRef:
      name: cephfs-secret
    readOnly: false
  persistentVolumeReclaimPolicy: Retain

创建PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: cephfs-pv-html
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

创建容器测试使用

apiVersion: v1
kind: ReplicationController
metadata: 
  name: nginx
spec:
  replicas: 1
  selector:
    app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports: 
        - containerPort: 80
        volumeMounts:
        - name: cephfs
          mountPath: /usr/share/nginx/html
      volumes:
      - name: cephfs
        persistentVolumeClaim:
          claimName: cephfs-pv-html