1、創建密鑰
進入ceph,獲取密鑰串
(假設ceph環境已經安裝完成:10.41.10.81,10.41.10.82,10.41.10.83)
#進入ceph集羣的管理主機
ceph auth get-key client.admin | base64
#得到這個串,下面使用
進入k8s,創建密鑰
cat <<eof >ceph-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: ceph-secret
data:
key: 這裏輸入上面得到的串
eof
kubectl apply -f ceph-secret.yaml #添加密碼
2、添加一個部署,在其中添加需要的ceph目錄(在這之前,請先掛載ceph,並在裏面添加指定的目錄)
cat <<eof >test-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 2
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: docker.io/centos
command: ["/bin/sh"]
args: ["-c","while true;do echo hello;sleep 1000;done"]
volumeMounts:
- mountPath: "/conf"
name: conf
volumes:
- name: conf
cephfs:
monitors:
- 10.41.10.81:6789,10.41.10.82:6789,10.41.10.83:6789
path: /test/conf
user: admin
readOnly: false
secretRef:
name: ceph-secret
eof
kubectl apply -f test.deployment.yaml
完成!
附:掛載ceph目錄
mount -t ceph \
10.41.10.81:6789,10.41.10.82:6789,10.41.10.83:6789:/ \
/ceph -o name=admin,secret=************ #這裏的密鑰就是我們在ceph服務器中獲取到的密鑰串