vSphere Container Storage Plug-in supports XFS file system for PVCs with ReadWriteOnce
access mode and Filesystem
volume mode.
The following example explains how XFS file system is used to mount a volume inside the mongo database application.
Prerequisites
Specify XFS as the
csi.storage.k8s.io/fstype
under the storage class to use XFS file system to format and mount volume inside the container.
Note: XFS file system support for
vSphere Container Storage Plug-in is validated using Ubuntu 20.04.2 LTS with kernel version 5.4.0-66-generic. However,
vSphere Container Storage Plug-in is currently not compatible with the XFS file system on CentOS 7, and Red Hat Enterprise Linux 7 due to issues with xfsprogs 5.8.0-1.ph4 and respective kernels.
Procedure
- Create a Storage Class.
- Use the following manifest as
mongo-sc.yaml
.kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: example-mongo-sc annotations: storageclass.kubernetes.io/is-default-class: "true" # Optional provisioner: csi.vsphere.vmware.com allowVolumeExpansion: true # Optional: only applicable to vSphere 7.0U1 and above parameters: storagepolicyname: "vSAN Default Storage Policy" # Optional Parameter csi.storage.k8s.io/fstype: "xfs" # Optional Parameter
- Create a Storage Class.
kubectl create -f mongo-sc.yaml
- Use the following manifest as
- Create PVC.
- Use the following manifest as
mongo-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: example-mongo-data spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi storageClassName: example-mongo-sc
- Create PVC.
kubectl create -f mongo-pvc.yaml
- Use the following manifest as
- Create
mongodb
secrets.- Use the following manifest as
mongo-secrets.yaml
.apiVersion: v1 data: password: cGFzc3dvcmQxMjM= #password123 username: YWRtaW51c2Vy #adminuser kind: Secret metadata: creationTimestamp:null name: mongo-creds
- Create the secret.
kubectl create -f mongo-secrets.yaml
- Use the following manifest as
- Deploy
mongodb
.- Use the the following manifest as
mongo-deployment.yaml
.apiVersion: apps/v1 kind: Deployment metadata: labels: app: mongo name: mongo spec: replicas: 1 selector: matchLabels: app: mongo strategy: {} template: metadata: labels: app: mongo spec: containers: - image: mongo name: mongo args: ["--dbpath","/data/db"] env: - name: MONGO_INITDB_ROOT_USERNAME valueFrom: secretKeyRef: name: mongo-creds key: username - name: MONGO_INITDB_ROOT_PASSWORD valueFrom: secretKeyRef: name: mongo-creds key: password volumeMounts: - name: "mongo-data-dir" mountPath: "/data/db" volumes: - name: "mongo-data-dir" persistentVolumeClaim: claimName: "example-mongo-data"
- Create the deployment.
kubectl create -f mongo-deployment.yaml
- Verify if the file system used to mount volume inside the mongodb pod is XFS using the following command.
kubectl exec deployment/mongo -it -- /bin/bash # mount | grep xfs /dev/sdb on /data/db type xfs (rw,relatime,nouuid,attr2,inode64,logbufs=8,logbsize=32k,noquota)
- Use the the following manifest as
- Create
mongodb
node port service.- Use the following manifest as
mongo-nodeport-svc.yaml
.apiVersion: v1 kind: Service metadata: labels: app: mongo name: mongo-nodeport-svc spec: ports: - port:27017 protocol: TCP targetPort:27017 nodePort:32000 selector: app: mongo type: NodePort
- Create the service.
kubectl create -f mongo-nodeport-svc.yaml
- To connect to
mongodb
outside the kubernetes cluster, use the worker node IP address or a load balancer address.mongo --host <ip> --port <port of nodeport svc> -u adminuser -p password123
- Use the following manifest as
- Access
mongodb
.- Display the list of database.
test> show dbs admin 100.00 KiB config 12.00 KiB local 72.00 KiB
- Access a particular database.
test> use db1 switched to db db1
- Display the list of collection inside the db1 database.
db1> show collections
- Insert data from the db1 database.
db1> db.blogs.insertOne({name: "devopscube" }) { acknowledged: true, insertedIds: { '0': ObjectId("63da54d31b1b7f11e9cefb35") } }
- Display data from the db1 database.
db1> db.blogs.find() [ { _id: ObjectId("63da54d31b1b7f11e9cefb35"), name: 'devopscube' } ]
- Display the list of database.