kubernetes掛載cephfs

wang_0720發表於2018-01-30
1 生成ceph-secret

cat /etc/ceph/ceph.client.admin.keyring 
[client.admin]
key = AQDlG99ZVJhfExAAFVT/ttJBgqOKcyY5INX5Cw==

將key base64處理
echo "AQDlG99ZVJhfExAAFVT/ttJBgqOKcyY5INX5Cw=="|base64
QVFEbEc5OVpWSmhmRXhBQUZWVC90dEpCZ3FPS2N5WTVJTlg1Q3c9PQo=


2 建立secret

cat ceph-secret.yml 
apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
data:
  key: QVFEbEc5OVpWSmhmRXhBQUZWVC90dEpCZ3FPS2N5WTVJTlg1Q3c9PQo=

3 建立pvc

cat ceph-pvc.yml 
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: cephfs
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 8Gi

4 建立pv
cat ceph-pv.yml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: cephfs
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  cephfs:
    monitors:
    - 192.168.100.96:6789
    path: /
    user: admin
    secretRef:
      name: ceph-secret

5 建立RC

cat app-rc.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: rc-fish
  labels:
    name: fish
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: fish
    spec:
      containers:
      - name: fish
        image: registry:5000/fish:7.5
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 128Mi
        volumeMounts:
        - name: cephfs
          mountPath: /var/log/nginx
      volumes:
      - name: cephfs
        persistentVolumeClaim:
          claimName: cephfs

依次建立secret,pvc,pv,RC
kubectl create -f ceph-secret.yml
kubectl create -f ceph-pvc.yml
kubectl create -f ceph-pv.yml
kubectl create -f app-rc.yaml
檢視建立的secret,pvc,pv
root@mon2:~# kubectl get secrets
NAME                  TYPE                                  DATA      AGE
ceph-secret           Opaque                                1         3d
default-token-50p5c   kubernetes.io/service-account-token   3         3d
root@mon2:~# kubectl get pvc
NAME      STATUS    VOLUME    CAPACITY   ACCESSMODES   STORAGECLASS   AGE
cephfs    Bound     cephfs    10Gi       RWX                          3d
root@mon2:~# kubectl get pv
NAME      CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM            STORAGECLASS   REASON    AGE
cephfs    10Gi       RWX           Retain          Bound     default/cephfs                            3d

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-2150648/,如需轉載,請註明出處,否則將追究法律責任。