欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

k8s学习笔记——k8s pv rbd手动挂载

程序员文章站 2024-03-13 09:04:15
...

//创建image

ceph osd pool create kube 9 9 //可做或者使用默认的rbd
rbd pool init kube
rbd create --size 2048 kube/static_pv

//获取管理key并进行64位编码

ceph auth get-key client.admin | base64

将内容保存下来

//创建secret(ceph-secret-default.yaml)

apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
  namespace: default
type: "kubernetes.io/rbd"
data:
  key: QVFCTVQrUmdxYkxzTUJBQS90ZExaTUVBNjY5bmxtODJkNitCeXc9PQ==  #这里的key就是上步保存的信息

 //创建pv (nginx-pv.yaml)

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  rbd:
    monitors:
      - 10.12.70.201:6789,10.12.70.202:6789,10.12.70.203:6789
    pool: kube
    image: static_pv
    user: admin
    secretRef:
      name: ceph-secret
    fsType: xfs
    readOnly: false
  persistentVolumeReclaimPolicy: Recycle

//创建pvc(nginx-pvc.yaml)

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nginx-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

//创建应用(nginx-deploy.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
spec:
  selector:
    matchLabels:
      app: demo
  replicas: 1
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: demo
        image: busybox
        command: ["sleep", "6000"]
        volumeMounts:
          - mountPath: "/usr/share/busybox"
            name: data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: nginx-pvc

//执行yaml

kubectl apply -f ceph-secret-default.yaml
kubectl apply -f nginx-pv.yaml
kubectl apply -f nginx-pvc.yaml 
kubectl apply -f nginx-deploy.yaml   

//查看

//kubectl get secret

NAME                       TYPE                                  DATA   AGE
ceph-secret                kubernetes.io/rbd                     1      6d3h

//kubectl get pvc

NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
nginx-pvc       Bound    nginx-pv                                   1Gi        RWO                           5d20h

//kubectl get pv

NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                   STORAGECLASS   REASON   AGE
nginx-pv                                   1Gi        RWO            Recycle          Bound    default/nginx-pvc                               5d20h



//kubectl get pod
NAME                               READY   STATUS    RESTARTS   AGE

demo-9bbc4dd6f-f7kf4               1/1     Running   84         5d20h


//查看挂载是否成功

//kubectl exec -it demo-9bbc4dd6f-f7kf4 -- /bin/sh

//mount |grep rbd
/dev/rbd0 on /usr/share/busybox type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=64k,sunit=128,swidth=128,noquota)

//或者df |grep rbd
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/rbd0              1038336     40504    997832   4% /usr/share/busybox

像上面的内容的说明挂载成功了

相关标签: 网管笔记