[root@imwl-01 ~]# kubectl get pv |grep pvc-demo pvc-ed593fbd-2475-43fd-a946-2e2d5fb0c582 1Gi RWO Delete Bound default/pvc-demo rook-ceph-block 61s [root@imwl-01 ~]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE pvc-demo Bound pvc-ed593fbd-2475-43fd-a946-2e2d5fb0c582 1Gi RWO rook-ceph-block 64s [root@imwl-01 ~]# kubectl get pod NAME READY STATUS RESTARTS AGE pod-demo 1/1 Running 0 21m
[root@imwl-01 ~]# kubectl exec -it pod-demo -- ls -l /usr/share/nginx/html # 有挂载上 total 16 drwx------ 2 root root 16384 Mar 27 08:42 lost+found
apiVersion:storage.k8s.io/v1 kind:StorageClass metadata: name:rook-cephfs # Change "rook-ceph" provisioner prefix to match the operator namespace if needed provisioner:rook-ceph.cephfs.csi.ceph.com allowVolumeExpansion:true parameters: # clusterID is the namespace where operator is deployed. clusterID:rook-ceph
# CephFS filesystem name into which the volume shall be created fsName:myfs# 与上面的对应
# Ceph pool into which the volume shall be created # Required for provisionVolume: "true" pool:myfs-data0
# The secrets contain Ceph admin credentials. These are generated automatically by the operator # in the same namespace as the cluster. csi.storage.k8s.io/provisioner-secret-name:rook-csi-cephfs-provisioner csi.storage.k8s.io/provisioner-secret-namespace:rook-ceph csi.storage.k8s.io/controller-expand-secret-name:rook-csi-cephfs-provisioner csi.storage.k8s.io/controller-expand-secret-namespace:rook-ceph csi.storage.k8s.io/node-stage-secret-name:rook-csi-cephfs-node csi.storage.k8s.io/node-stage-secret-namespace:rook-ceph
reclaimPolicy:Delete
确认 mds pod 起来了、StorageClass 和文件系统都在:
1 2 3 4 5 6 7 8 9 10 11 12
[root@imwl-175 ~]# kubectl -n rook-ceph get pod -l app=rook-ceph-mds NAME READY STATUS RESTARTS AGE rook-ceph-mds-myfs-a-c676cc498-nknl4 1/1 Running 0 22h rook-ceph-mds-myfs-b-545776bddb-nxw4l 1/1 Running 0 22h
[root@imwl-175 ~]# kubectl get storageclasses.storage.k8s.io NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE rook-ceph-block rook-ceph.rbd.csi.ceph.com Delete Immediate true 20h rook-cephfs rook-ceph.cephfs.csi.ceph.com Delete Immediate true 14m
[root@imwl-175 ~]# kubectl exec -it -n rook-ceph $(kubectl get pod -n rook-ceph -l app=rook-ceph-tools -o=jsonpath='{.items[0].metadata.name}') -- ceph fs ls name: myfs, metadata pool: myfs-metadata, data pools: [myfs-data0 ]
[root@imwl-01 ceph]# kubectl get pod NAME READY STATUS RESTARTS AGE myapp-deployment-79c9bf589c-hgkrk 1/1 Running 0 21m myapp-deployment-79c9bf589c-hm856 1/1 Running 0 21m myapp-deployment-79c9bf589c-lbtck 1/1 Running 0 21m
[root@imwl-01 ceph]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE cephfs-pvc Bound pvc-929a3293-4bc5-46f6-be7e-782fbf822149 1Gi RWX rook-cephfs 22m
[root@imwl-01 ceph]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-929a3293-4bc5-46f6-be7e-782fbf822149 1Gi RWX Delete Bound default/cephfs-pvc rook-cephfs 22m
apiVersion:ceph.rook.io/v1 kind:CephObjectStore metadata: name:my-store namespace:rook-ceph# namespace:cluster spec: # The pool spec used to create the metadata pools. Must use replication. metadataPool: failureDomain:host replicated: size:3 # Disallow setting pool with replica 1, this could lead to data loss without recovery. # Make sure you're *ABSOLUTELY CERTAIN* that is what you want requireSafeReplicaSize:true parameters: # Inline compression mode for the data pool # Further reference: https://docs.ceph.com/docs/master/rados/configuration/bluestore-config-ref/#inline-compression compression_mode:none # gives a hint (%) to Ceph in terms of expected consumption of the total cluster capacity of a given pool # for more info: https://docs.ceph.com/docs/master/rados/operations/placement-groups/#specifying-expected-pool-size #target_size_ratio: ".5" # The pool spec used to create the data pool. Can use replication or erasure coding. dataPool: failureDomain:host replicated: size:3 requireSafeReplicaSize:true parameters: compression_mode:none #target_size_ratio: ".5" # Whether to preserve metadata and data pools on object store deletion preservePoolsOnDelete:false # The gateway service configuration gateway: # A reference to the secret in the rook namespace where the ssl certificate is stored # sslCertificateRef: # A reference to the secret in the rook namespace where the ca bundle is stored # caBundleRef: # The port that RGW pods will listen on (http) port:80 # The port that RGW pods will listen on (https). An ssl certificate is required. # securePort: 443 # The number of pods in the rgw deployment instances:1 # The affinity rules to apply to the rgw deployment. placement: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: -weight:100 podAffinityTerm: labelSelector: matchExpressions: -key:app operator:In values: -rook-ceph-rgw # topologyKey: */zone can be used to spread RGW across different AZ # Use <topologyKey: failure-domain.beta.kubernetes.io/zone> in k8s cluster if your cluster is v1.16 or lower # Use <topologyKey: topology.kubernetes.io/zone> in k8s cluster is v1.17 or upper topologyKey:kubernetes.io/hostname # A key/value list of annotations annotations: # A key/value list of labels labels: resources: # The requests and limits set here, allow the object store gateway Pod(s) to use half of one CPU core and 1 gigabyte of memory # limits: # cpu: "500m" # memory: "1024Mi" # requests: # cpu: "500m" # memory: "1024Mi" priorityClassName:system-cluster-critical # service endpoint healthcheck healthCheck: # Configure the pod probes for the rgw daemon startupProbe: disabled:false readinessProbe: disabled:false # security oriented settings # security: # To enable the Server Side Encryption configuration properly don't forget to uncomment the Secret at the end of the file # kms: # configures RGW with AWS-SSE:KMS # # name of the config map containing all the kms connection details # connectionDetails: # KMS_PROVIDER: "vault" # VAULT_ADDR: VAULT_ADDR_CHANGE_ME # e,g: http://vault.my-domain.com:8200 # VAULT_BACKEND_PATH: "rook" # VAULT_SECRET_ENGINE: "kv" # VAULT_BACKEND: v2 # # name of the secret containing the kms authentication token # tokenSecretName: rook-vault-token # s3: # configures RGW with AWS-SSE:S3 # # name of the config map containing all the kms connection details # connectionDetails: # KMS_PROVIDER: "vault" # VAULT_ADDR: VAULT_ADDR_CHANGE_ME # e,g: http://vault.my-domain.com:8200 # VAULT_BACKEND_PATH: "rook" # VAULT_SECRET_ENGINE: "transit" # # name of the secret containing the kms authentication token # tokenSecretName: rook-vault-token # # UNCOMMENT THIS TO ENABLE A KMS CONNECTION # # Also, do not forget to replace both: # # * ROOK_TOKEN_CHANGE_ME: with a base64 encoded value of the token to use # # * VAULT_ADDR_CHANGE_ME: with the Vault address # --- # apiVersion: v1 # kind: Secret # metadata: # name: rook-vault-token # namespace: rook-ceph # namespace:cluster # data: # token: ROOK_TOKEN_CHANGE_ME
apiVersion:storage.k8s.io/v1 kind:StorageClass metadata: name:rook-ceph-delete-bucket provisioner:rook-ceph.ceph.rook.io/bucket# driver:namespace:cluster # set the reclaim policy to delete the bucket and all objects # when its OBC is deleted. reclaimPolicy:Delete parameters: objectStoreName:my-store objectStoreNamespace:rook-ceph# namespace:cluster # To accommodate brownfield cases reference the existing bucket name here instead # of in the ObjectBucketClaim (OBC). In this case the provisioner will grant # access to the bucket by creating a new user, attaching it to the bucket, and # providing the credentials via a Secret in the namespace of the requesting OBC. #bucketName:
apiVersion:objectbucket.io/v1alpha1 kind:ObjectBucketClaim metadata: name:ceph-delete-bucket spec: # To create a new bucket specify either `bucketName` or # `generateBucketName` here. Both cannot be used. To access # an existing bucket the bucket name needs to be defined in # the StorageClass referenced here, and both `bucketName` and # `generateBucketName` must be omitted in the OBC. #bucketName: generateBucketName:ceph-bkt storageClassName:rook-ceph-delete-bucket additionalConfig: # To set for quota for OBC #maxObjects: "1000" #maxSize: "2G"
[root@imwl-01 ceph]# kubectl -n rook-ceph get pod -l app=rook-ceph-rgw NAME READY STATUS RESTARTS AGE rook-ceph-rgw-my-store-a-74d58648b8-5r9r2 2/2 Running 0 2m27s
[root@imwl-01 ceph]# kubectl -n rook-ceph get svc -l app=rook-ceph-rgw NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE rook-ceph-rgw-my-store ClusterIP 10.68.25.246 <none> 80/TCP 14m rook-ceph-rgw-my-store-external NodePort 10.68.15.54 <none> 80:31088/TCP 4m20s
Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options.
Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables. Access Key: <REDACTED_ACCESS_KEY> Secret Key: <REDACTED_SECRET_KEY> Default Region [US]:
Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3. S3 Endpoint [s3.amazonaws.com]: rook-ceph-rgw-my-store.rook-ceph.svc:80
Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used if the target S3 system supports dns based buckets. DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: rook-ceph-rgw-my-store.rook-ceph.svc:80/%(bucket)
Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: Path to GPG program [/usr/bin/gpg]:
When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP, and can only be proxied with Python 2.7 or newer Use HTTPS protocol [Yes]: no
On some networks all internet access must go through a HTTP proxy. Try setting it here if you can't connect to S3 directly HTTP Proxy server name:
Test access with supplied credentials? [Y/n] y Please wait, attempting to list all buckets... Success. Your access key and secret key worked fine :-)
Now verifying that encryption works... Not configured. Never mind.
Save settings? [y/N] y Configuration saved to '/root/.s3cfg'
上传、下载、删除都正常:
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@rook-ceph-tools-8558bfc844-9rmjm /]# s3cmd ls 2023-03-27 09:59 s3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7 [root@rook-ceph-tools-8558bfc844-9rmjm /]# s3cmd put /etc/passwd* s3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7 upload: '/etc/passwd' -> 's3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7/passwd' [1 of 2] 1295 of 1295 100% in 0s 91.34 KB/s done upload: '/etc/passwd-' -> 's3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7/passwd-' [2 of 2] 1231 of 1231 100% in 0s 23.42 KB/s done
[root@rook-ceph-tools-8558bfc844-9rmjm /]# s3cmd get s3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7/passwd ./ download: 's3://ceph-bkt-1afbdd70-2a65-4aad-9e7a-8c7b3bd5acb7/passwd' -> './passwd' [1 of 1]
[root@imwl-01 ~]# kubectl -n rook-ceph get secrets rook-ceph-object-user-my-store-my-user NAME TYPE DATA AGE rook-ceph-object-user-my-store-my-user kubernetes.io/rook 3 42s
[root@imwl-01 external-snapshotter-master]# kubectl get pods -n kube-system -l app=snapshot-controller NAME READY STATUS RESTARTS AGE snapshot-controller-5899869978-4xwxq 1/1 Running 0 51m snapshot-controller-5899869978-95nth 1/1 Running 0 52m
rbd 快照与恢复
先建一个 rbd 的 VolumeSnapshotClass:
1 2 3 4 5 6 7 8 9 10 11 12 13
apiVersion:snapshot.storage.k8s.io/v1 kind:VolumeSnapshotClass metadata: name:csi-rbdplugin-snapclass driver:rook-ceph.rbd.csi.ceph.com# driver:namespace:operator parameters: # Specify a string that identifies your cluster. Ceph CSI supports any # unique string. When Ceph CSI is deployed by Rook use the Rook namespace, # for example "rook-ceph". clusterID:rook-ceph# namespace:cluster csi.storage.k8s.io/snapshotter-secret-name:rook-csi-rbd-provisioner csi.storage.k8s.io/snapshotter-secret-namespace:rook-ceph# deletionPolicy:Delete
[root@imwl-03 ceph]# rbd info ceph-demo/rdb-demo.img | grep size # 块设备扩容成功 size 2 GiB in 512 objects
[root@imwl-03 ceph]# df -h /media # 文件系统未扩容 Filesystem Size Used Avail Use% Mounted on /dev/rbd0 974M 28K 907M 1% /media
[root@imwl-03 ceph]# resize2fs /dev/rbd0 # 扩容文件系统 resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/rbd0 is mounted on /media; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/rbd0 is now 524288 (4k) blocks long.
[root@imwl-03 ceph]# df -h /media # 文件系统扩容成功 Filesystem Size Used Avail Use% Mounted on /dev/rbd0 2.0G 28K 1.9G 1% /media
[root@imwl-03 ceph]# ceph health detail # 集群健康详细 HEALTH_WARN 1 pool(s) do not have an application enabled; 1 mgr modules have recently crashed [WRN] POOL_APP_NOT_ENABLED: 1 pool(s) do not have an application enabled application not enabled on pool 'ceph-demo' use 'ceph osd pool application enable <pool-name> <app-name>', where <app-name> is 'cephfs', 'rbd', 'rgw', or freeform for custom applications.
[root@imwl-03 ceph]# ceph osd pool application get ceph-demo # 查看当前 pool 的 application 定义 {}
[root@imwl-03 ceph]# ceph osd pool application enable ceph-demo rbd # 设置资源池的类型,方便管理 enabled application 'rbd' on pool 'ceph-demo'
[root@imwl-03 ceph]# ceph osd pool application get ceph-demo { "rbd": {} }
# 上面 health detail 里其实是两条告警,POOL_APP_NOT_ENABLED 只是其中一条; # 另一条 RECENT_MGR_MODULE_CRASH 不会因为给 pool 打了 application 标记而消失,得单独归档: [root@imwl-03 ceph]# ceph crash archive-all