k8s使用cephfs

以下为ceph集群操作内容


cephfs

将cephfs挂载到一台服务器 /mnt/cephf 。

创建目录 mkdir -p /mnt/cephf/k8s/staff-nginx/{conf,data}

 

以下为k8s节点操作内容


创建secret

 

[root@ceph1 wsjy-proxy]# ceph auth get-key client.admin|base64
QVFDM2k3MWNZeXIyTFJBQU1JcFp0eG5VdVlyYURNSUcyMVgyVnc11Q==

[root@node1 work]# vim ceph-secret3.yaml 
apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
data:
  key: QVFDM2k3MWNZeXIyTFJBQU1JcFp0eG5VdVlyYURNSUcyMVgyVnc11Q==
[root@node1 work]# kubectl create -f ceph-secret3.yaml 
secret "ceph-secret" created
[root@node1 work]# kubectl get secret                  
NAME                  TYPE                                  DATA      AGE
ceph-secret           Opaque                                1         2s
default-token-7s88r   kubernetes.io/service-account-token   3         12d

 

创建pv

 

[root@node1 staff-nginx]# cat staff-nginx-pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: staff-nginx-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  cephfs:
    monitors:
      - 10.101.71.150:6789,10.101.71.151:6789,10.101.71.152:6789
    path: /k8s/staff-nginx
    user: admin
    readOnly: false
    secretRef:
      name: ceph-secret
  persistentVolumeReclaimPolicy: Recycle

[root@node1 staff-nginx]# kubectl get pv
NAME                    CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                            STORAGECLASS   REASON   AGE
staff-nginx-pv          2Gi        RWX            Recycle          Bound    default/staff-nginx-pvc                                  172m

 

 

创建pvc

 

[root@node1 staff-nginx]# cat staff-nginx-pvc.yaml 
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: staff-nginx-pvc 
spec:
  accessModes:
    - ReadWriteMany
  volumeName: staff-nginx-pv
  resources:
    requests:
      storage: 2Gi
[root@node1 staff-nginx]# kubectl get pvc
NAME                     STATUS   VOLUME                  CAPACITY   ACCESS MODES   STORAGECLASS   AGE
staff-nginx-pvc          Bound    staff-nginx-pv          2Gi        RWX                           173m

 

创建POD

 

[root@node1 staff-nginx]# cat staff-nginx.yaml 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dep-staff-nginx
  namespace: default
spec:
  replicas: 2
  template:
    metadata:
      labels:
        name: staff-nginx
    spec:
      containers:
      - name: staff-nginx
        image: nginx:1.7.9
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: "500m"
            memory: 512Mi
          requests:
            cpu: "250m"
            memory: 256Mi
        env:
        - name: TZ
          value: "Asia/Shanghai"
        ports:
        - name: tcp80
          containerPort: 80
        volumeMounts:
          - mountPath: "/usr/share/nginx/html"
            name: nginx-data
            subPath: data
          - mountPath: "/etc/nginx/conf.d"
            name: staff-nginx-data
            subPath: conf
#          - mountPath: "/etc/nginx/nginx.conf"
#            name: staff-nginx-data
#            subPath: nginx.conf
      
      volumes:
        - name: staff-nginx-data
          persistentVolumeClaim:
            claimName: staff-nginx-pvc      

      nodeSelector:
        node: "master"  

---
kind: Service
apiVersion: v1
metadata:
  name: staff-proxy-service
  labels:
    name: staff-proxy-service 
spec:
  type: NodePort
  selector:
    name: staff-nginx
  ports:
    - name: tcp80
      port: 80
      targetPort: 80
      nodePort: 30080

转载于:https://www.cnblogs.com/bugbeta/p/10882149.html

你可能感兴趣的:(k8s使用cephfs)