diff --git a/README.md b/README.md index aa4e8d0..929667d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ tldr; Watch introduction & Demo Video [here](https://www.youtube.com/watch?v=mae ### CRC / OC Binaries - Download CRC and OC binaries from [cloud.redhat.com]((https://cloud.redhat.com/openshift/create/local) - Create CRC directlry `mkdir ~/.crc` +- configure crcssh `./configure_crcssh.sh` - Also get CRC pull secret from [cloud.redhat.com]((https://cloud.redhat.com/openshift/create/local) and save it as `~/.crc/pull-secret.txt` ## Step -1 :: Deploy CRC - Linux ### Watch Demo Video [here](https://www.youtube.com/watch?v=mae0tiLkQag) @@ -54,6 +55,7 @@ crc console --credentials > crc-creds.txt ### Prerequisites - SSH into the host machine running CRC VM - Create a few raw devices that `ODF-Nano` will use +- You can also run `./generate_volumes.sh` ``` ## Don't worry this is thin provisioned sudo -S qemu-img create -f raw ~/.crc/vdb 100G @@ -200,6 +202,11 @@ oc get sc ``` - You now have File/Block/Object Persistent Storage Classes from ODF. Deploy and Test your app locally, like you do in production (OCP & ODF) +- Optional: Define default storage class +``` + oc patch storageclass ocs-storagecluster-ceph-rbd -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}} +``` + ![ODF Storage Classes](assets/odf-sc.png) # Miscelleanous diff --git a/configure_crcssh.sh b/configure_crcssh.sh new file mode 100755 index 0000000..bf8ec01 --- /dev/null +++ b/configure_crcssh.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if grep -q "crcssh=" ~/.bash_aliases +then + echo "crcssh already exists in ~/.bash_aliases " +else + echo "alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa -o StrictHostKeyChecking=no core@`crc ip`'" >> ~/.bash_aliases +fi diff --git a/deploy_odf.sh b/deploy_odf.sh index ac56681..1c3c42f 100755 --- a/deploy_odf.sh +++ b/deploy_odf.sh @@ -6,6 +6,7 @@ #!/bin/bash set +x echo "Setting up environment for ODF - this will take a few minutes" +VOLUME_COUNT="$(ls ~/.crc/vd* | wc -l)" oc label "$(oc get no -o name)" cluster.ocs.openshift.io/openshift-storage='' --overwrite >/dev/null @@ -82,44 +83,32 @@ apiVersion: storage.k8s.io/v1 metadata: name: localblock provisioner: kubernetes.io/no-provisioner +EOF + + +for vdisk in ~/.crc/vd* +do + virtual_disk="${vdisk##*/}" + virtual_drive="${virtual_disk%.*}" + + echo "Create local-pv-${virtual_drive} for ODF-Nano" + disk_size=$(ls -lath ~/.crc/${virtual_drive} | grep -oE [0-9]{3}G) +cat </dev/null --- apiVersion: v1 kind: PersistentVolume metadata: - name: local-pv-vdb -spec: - capacity: - storage: 100Gi - volumeMode: Block - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Delete - storageClassName: localblock - local: - path: /dev/vdb - nodeAffinity: - required: - nodeSelectorTerms: - - matchExpressions: - - key: node.openshift.io/os_id - operator: In - values: - - rhcos ---- -apiVersion: v1 -kind: PersistentVolume -metadata: - name: local-pv-vdc + name: local-pv-${virtual_drive} spec: capacity: - storage: 100Gi + storage: ${disk_size}i volumeMode: Block accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: localblock local: - path: /dev/vdc + path: /dev/${virtual_drive} nodeAffinity: required: nodeSelectorTerms: @@ -129,6 +118,8 @@ spec: values: - rhcos EOF +sleep 2s +done seq 20 30 | xargs -n1 -P0 -I {} oc patch pv/pv00{} -p '{"metadata":{"annotations":{"volume.beta.kubernetes.io/storage-class": "localfile"}}}' >/dev/null @@ -153,7 +144,7 @@ data: mon_osd_nearfull_ratio = .75 mon_max_pg_per_osd = 600 osd_pool_default_min_size = 1 - osd_pool_default_size = 2 + osd_pool_default_size = ${VOLUME_COUNT} [osd] osd_memory_target_cgroup_limit_ratio = 0.5 kind: ConfigMap @@ -221,7 +212,7 @@ spec: manageNodes: false monDataDirHostPath: /var/lib/rook storageDeviceSets: - - count: 2 + - count: ${VOLUME_COUNT} dataPVCTemplate: spec: accessModes: @@ -336,7 +327,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} metadataPool: compressionMode: "" crushRoot: "" @@ -349,7 +340,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} metadataServer: activeCount: 1 activeStandby: false @@ -444,7 +435,7 @@ spec: failureDomain: osd replicated: requireSafeReplicaSize: false - size: 2 + size: ${VOLUME_COUNT} gateway: allNodes: false instances: 1 @@ -462,7 +453,7 @@ spec: dataChunks: 0 failureDomain: osd replicated: - size: 2 + size: ${VOLUME_COUNT} requireSafeReplicaSize: false EOF @@ -506,3 +497,4 @@ spec: EOF echo "ODF is installed now" + diff --git a/generate_volumes.sh b/generate_volumes.sh new file mode 100755 index 0000000..cbb1413 --- /dev/null +++ b/generate_volumes.sh @@ -0,0 +1,114 @@ +#!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases + +read -p "Enter volume count Example: 2 > " VOLUME_COUNT +read -p "Enter volume size Example: 100 > " VOLUME_SIZE + +if [ ${VOLUME_COUNT} -gt 5 ]; +then + echo "Volume count of ${VOLUME_COUNT} is too high" + echo "A max of five volumes may be added." + exit 1 +fi + + +if [ ${VOLUME_COUNT} -lt 2 ]; +then + echo "setting default volume count to 2" + VOLUME_COUNT=2 +fi + +if [ ${VOLUME_SIZE} -lt 100 ] +then + echo "setting default volume size to 100" + VOLUME_SIZE=100 +fi + +virtual_drive[1]="vdb" +virtual_drive[2]="vdc" +virtual_drive[3]="vdd" +virtual_drive[4]="vde" +virtual_drive[5]="vdf" + +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo "Create ${virtual_drive[$i]} for ODF-Nano" + sudo -S qemu-img create -f raw ~/.crc/${virtual_drive[$i]} ${VOLUME_SIZE}G +done + +CRC_STATUS=$(crc status | grep "CRC VM:" | awk '{print $3}') +if [ $CRC_STATUS == "Running" ]; +then + echo "crc stop" + crc stop +fi +sudo virsh list --all +sudo virsh dumpxml crc > ~/crc.xml + +BUS=$(grep -o '0x03' ~/crc.xml| egrep -o '.{1}$') + +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo "Checking that ${virtual_drive[$i]} exists on crc" + if grep '/home/admin/.crc/'${virtual_drive[$i]}'' ~/crc.xml > /dev/null + then + echo "$HOME/.crc/${virtual_drive[$i]} already exists in ~/crc.xml" + exit 1 + fi +done + +if [ ${BUS} -ne 3 ]; +then + echo "Incorrect address bus for drive" + exit 1 +fi + +if [ -f ~/crc-patch.xml ]; +then + rm ~/crc-patch.xml + touch ~/crc-patch.xml +else + touch ~/crc-patch.xml +fi + +echo ' ' > ~/crc-patch.xml +for (( i = 1; i <= $VOLUME_COUNT; i++ )) +do + echo ${virtual_drive[$i]} + address_bus=$(($BUS + $i + 1)) + +sudo tee -a ~/crc-patch.xml > /dev/null < + + + + + +
+ +EOT +done + +cp ~/crc.xml ~/crc-backup.xml + +line=$(grep -n '' ~/crc.xml | cut -d ":" -f 1) +line=$(grep -n '' ~/crc.xml | cut -d ":" -f 1) +{ head -n $(($line-1)) ~/crc.xml; cat ~/crc-patch.xml; tail -n +$(($line+1)) ~/crc.xml; } > ~/crc-mod.xml +cat ~/crc-mod.xml +sed -i "s|~|$HOME|g" ~/crc-mod.xml +sudo virsh define ~/crc-mod.xml || exit $? + +read -p "Would you like to start CRC? (y/n)" -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + crc start + echo "Block creation validation" + crcssh lsblk + + echo "To restore configutation run the following." + echo "$ sudo virsh define ~/crc-backup.xml" + echo "$ crc start " +fi + diff --git a/reconfigure_sizing.sh b/reconfigure_sizing.sh new file mode 100755 index 0000000..901fe24 --- /dev/null +++ b/reconfigure_sizing.sh @@ -0,0 +1,42 @@ +#!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases + +function configure_crc(){ + crc config set consent-telemetry no + crc config set enable-cluster-monitoring true + crc config set cpus ${1} + crc config set memory ${2} + crc config view +} + +read -p "Reconfigure CPUs Example: 15 > " CPU_COUNT +read -p "Reconfigure Memory size in MB Example: 60000 > " VOLUME_SIZE + + + +CRC_STATUS=$(crc status | grep "CRC VM:" | awk '{print $3}') + +if [ ${CRC_STATUS} == "Running" ]; +then + crc stop + configure_crc ${CPU_COUNT} ${VOLUME_SIZE} +else + configure_crc ${CPU_COUNT} ${VOLUME_SIZE} +fi + + +read -p "Would you like to start CRC? (y/n)" -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + crc start + echo "Block creation validation" + crcssh lsblk + + echo "To restore configutation run the following." + echo "$ sudo virsh define ~/crc-backup.xml" + echo "$ crc start " +fi + + diff --git a/uninstall_odf.sh b/uninstall_odf.sh old mode 100644 new mode 100755 index 81e913d..84cec80 --- a/uninstall_odf.sh +++ b/uninstall_odf.sh @@ -1,4 +1,6 @@ #!/bin/bash +shopt -s expand_aliases +source ~/.bash_aliases oc annotate storagecluster ocs-storagecluster uninstall.ocs.openshift.io/cleanup-policy="delete" --overwrite oc annotate storagecluster ocs-storagecluster uninstall.ocs.openshift.io/mode="forced" --overwrite @@ -31,9 +33,17 @@ oc project default for i in $(oc get node -l cluster.ocs.openshift.io/openshift-storage= -o jsonpath='{ .items[*].metadata.name }'); do oc debug node/${i} -- chroot /host rm -rfv /mnt/local-storage/${SC}/; done oc delete localvolumediscovery.local.storage.openshift.io/auto-discover-devices -n openshift-local-storage -alias crcssh='ssh -i ~/.crc/machines/crc/id_ecdsa core@"$(crc ip)"' -for i in vdb vdc ; do crcssh sudo wipefs -af /dev/$i ; done -for i in vdb vdc ; do crcssh sudo sgdisk --zap-all /dev/$i ; done -for i in vdb vdc ; do crcssh sudo dd if=/dev/zero of=/dev/$i bs=1M count=100 oflag=direct,dsync ; done -for i in vdb vdc ; do crcssh sudo blkdiscard /dev/$i ; done - +for vdisk in ~/.crc/vd* +do + virtual_disk="${vdisk##*/}" + virtual_drive="${virtual_disk%.*}" + echo "Wiping $virtual_drive" + echo "*********************" + crcssh sudo wipefs -af /dev/$virtual_drive ; + sleep 2s + crcssh sudo sgdisk --zap-all /dev/$virtual_drive + sleep 2s + crcssh sudo dd if=/dev/zero of=/dev/$virtual_drive bs=1M count=100 oflag=direct,dsync ; + sleep 2s + crcssh sudo blkdiscard /dev/$virtual_drive ; +done \ No newline at end of file