diff --git a/cs-offerings/kube-configs/blockchain-couchdb.yaml b/cs-offerings/kube-configs/blockchain-couchdb.yaml index fa6d9cd..c3b0247 100644 --- a/cs-offerings/kube-configs/blockchain-couchdb.yaml +++ b/cs-offerings/kube-configs/blockchain-couchdb.yaml @@ -70,11 +70,11 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc containers: - - name: pulse - image: ibmblockchain/fabric-tools:1.0.3 - command: ["sh", "-c", "sleep 1 && UUID=$(cat /proc/sys/kernel/random/uuid) && while [ true ]; do curl https://ics-endpoint.mybluemix.net/pulse/beat/$UUID; sleep 10; done"] - name: orderer image: ibmblockchain/fabric-orderer:1.0.3 command: ["sh", "-c", "sleep 5 && while [ ! -f /shared/bootstrapped ]; do echo Waiting for bootstrap; sleep 1; done; orderer"] @@ -84,7 +84,7 @@ spec: - name: ORDERER_GENERAL_LEDGERTYPE value: file - name: ORDERER_FILELEDGER_LOCATION - value: /mnt/ledger/orderer1 + value: /ledger/orderer/fileledger - name: ORDERER_GENERAL_BATCHTIMEOUT value: 1s - name: ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT @@ -116,6 +116,11 @@ spec: volumeMounts: - mountPath: /shared name: shared + - mountPath: /ledger + name: ledger + - name: pulse + image: ibmblockchain/fabric-tools:1.0.3 + command: ["sh", "-c", "sleep 1 && UUID=$(cat /proc/sys/kernel/random/uuid) && while [ true ]; do curl https://ics-endpoint.mybluemix.net/pulse/beat/$UUID; sleep 10; done"] --- apiVersion: extensions/v1beta1 @@ -175,6 +180,9 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc - name: dockersocket hostPath: path: /var/run/docker.sock @@ -186,10 +194,10 @@ spec: env: - name: CORE_PEER_ADDRESSAUTODETECT value: "true" - - name: CORE_PEER_ID - value: org1peer1 - name: CORE_PEER_NETWORKID value: nid1 + - name: CORE_PEER_ID + value: org1peer1 - name: CORE_PEER_ADDRESS value: blockchain-org1peer1:30110 - name: CORE_PEER_LISTENADDRESS @@ -234,6 +242,8 @@ spec: value: CouchDB - name: CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS value: blockchain-couchdb1:30984 + - name: CORE_PEER_FILESYSTEMPATH + value: /ledger/org1/peer1/ledger - name: FABRIC_CFG_PATH value: /etc/hyperledger/fabric/ - name: ORDERER_URL @@ -245,6 +255,8 @@ spec: volumeMounts: - mountPath: /shared name: shared + - mountPath: /ledger + name: ledger - mountPath: /host/var/run/docker.sock name: dockersocket --- @@ -263,6 +275,9 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc - name: dockersocket hostPath: path: /var/run/docker.sock @@ -300,6 +315,8 @@ spec: value: Org2MSP - name: CORE_PEER_MSPCONFIGPATH value: /shared/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/ + - name: CORE_PEER_FILESYSTEMPATH + value: /ledger/org2/peer1/ledger - name: CORE_LOGGING_LEVEL value: debug - name: CORE_LOGGING_PEER @@ -333,6 +350,8 @@ spec: volumeMounts: - mountPath: /shared name: shared + - mountPath: /ledger + name: ledger - mountPath: /host/var/run/docker.sock name: dockersocket @@ -348,12 +367,19 @@ spec: labels: name: couchdb1 spec: + volumes: + - name: couchdb1 + persistentVolumeClaim: + claimName: couchdb1-pvc containers: - name: couchdb1 image: ibmblockchain/fabric-couchdb:1.0.3 env: - name: DB_URL value: http://localhost:5984/member_db + volumeMounts: + - mountPath: /opt/couchdb/data + name: couchdb1 --- apiVersion: extensions/v1beta1 @@ -367,9 +393,16 @@ spec: labels: name: couchdb2 spec: + volumes: + - name: couchdb2 + persistentVolumeClaim: + claimName: couchdb2-pvc containers: - name: couchdb2 image: ibmblockchain/fabric-couchdb:1.0.3 env: - name: DB_URL value: http://localhost:5984/member_db + volumeMounts: + - mountPath: /opt/couchdb/data + name: couchdb2 diff --git a/cs-offerings/kube-configs/blockchain.yaml b/cs-offerings/kube-configs/blockchain.yaml index f40a8ac..1b115fb 100644 --- a/cs-offerings/kube-configs/blockchain.yaml +++ b/cs-offerings/kube-configs/blockchain.yaml @@ -70,11 +70,11 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc containers: - - name: pulse - image: ibmblockchain/fabric-tools:1.0.3 - command: ["sh", "-c", "sleep 1 && UUID=$(cat /proc/sys/kernel/random/uuid) && while [ true ]; do curl https://ics-endpoint.mybluemix.net/pulse/beat/$UUID; sleep 10; done"] - name: orderer image: ibmblockchain/fabric-orderer:1.0.3 command: ["sh", "-c", "sleep 5 && while [ ! -f /shared/bootstrapped ]; do echo Waiting for bootstrap; sleep 1; done; orderer"] @@ -84,7 +84,7 @@ spec: - name: ORDERER_GENERAL_LEDGERTYPE value: file - name: ORDERER_FILELEDGER_LOCATION - value: /mnt/ledger/orderer1 + value: /ledger/orderer/fileledger - name: ORDERER_GENERAL_BATCHTIMEOUT value: 1s - name: ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT @@ -116,7 +116,11 @@ spec: volumeMounts: - mountPath: /shared name: shared - + - mountPath: /ledger + name: ledger + - name: pulse + image: ibmblockchain/fabric-tools:1.0.3 + command: ["sh", "-c", "sleep 1 && UUID=$(cat /proc/sys/kernel/random/uuid) && while [ true ]; do curl https://ics-endpoint.mybluemix.net/pulse/beat/$UUID; sleep 10; done"] --- apiVersion: extensions/v1beta1 kind: Deployment @@ -175,6 +179,9 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc - name: dockersocket hostPath: path: /var/run/docker.sock @@ -232,6 +239,8 @@ spec: value: "false" - name: CORE_LEDGER_STATE_STATEDATABASE value: goleveldb + - name: CORE_PEER_FILESYSTEMPATH + value: /ledger/org1/peer1/ledger - name: FABRIC_CFG_PATH value: /etc/hyperledger/fabric/ - name: ORDERER_URL @@ -243,6 +252,8 @@ spec: volumeMounts: - mountPath: /shared name: shared + - mountPath: /ledger + name: ledger - mountPath: /host/var/run/docker.sock name: dockersocket --- @@ -261,6 +272,9 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc - name: dockersocket hostPath: path: /var/run/docker.sock @@ -298,6 +312,8 @@ spec: value: Org2MSP - name: CORE_PEER_MSPCONFIGPATH value: /shared/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/ + - name: CORE_PEER_FILESYSTEMPATH + value: /ledger/org2/peer1/ledger - name: CORE_LOGGING_LEVEL value: debug - name: CORE_LOGGING_PEER @@ -329,5 +345,7 @@ spec: volumeMounts: - mountPath: /shared name: shared + - mountPath: /ledger + name: ledger - mountPath: /host/var/run/docker.sock name: dockersocket diff --git a/cs-offerings/kube-configs/storage-couchdb-free.yaml b/cs-offerings/kube-configs/storage-couchdb-free.yaml new file mode 100644 index 0000000..4363985 --- /dev/null +++ b/cs-offerings/kube-configs/storage-couchdb-free.yaml @@ -0,0 +1,61 @@ +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: couchdb1-pv + labels: + type: local + name: couchdb1 +spec: + capacity: + storage: 20Gi + accessModes: + - ReadWriteMany + hostPath: + path: "/couchdb1" + +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: couchdb2-pv + labels: + type: local + name: couchdb2 +spec: + capacity: + storage: 20Gi + accessModes: + - ReadWriteMany + hostPath: + path: "/couchdb2" + +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: couchdb1-pvc +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi + selector: + matchLabels: + name: couchdb1 + +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: couchdb2-pvc +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi + selector: + matchLabels: + name: couchdb2 diff --git a/cs-offerings/kube-configs/storage-couchdb-paid.yaml b/cs-offerings/kube-configs/storage-couchdb-paid.yaml new file mode 100644 index 0000000..e786bc8 --- /dev/null +++ b/cs-offerings/kube-configs/storage-couchdb-paid.yaml @@ -0,0 +1,33 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: couchdb1-pvc + annotations: + #ibmc-file-bronze: 2 IOPS per GB. + #ibmc-file-silver: 4 IOPS per GB. + #ibmc-file-gold: 10 IOPS per GB. + volume.beta.kubernetes.io/storage-class: "ibmc-file-silver" +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 20Gi + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: couchdb2-pvc + annotations: + #ibmc-file-bronze: 2 IOPS per GB. + #ibmc-file-silver: 4 IOPS per GB. + #ibmc-file-gold: 10 IOPS per GB. + volume.beta.kubernetes.io/storage-class: "ibmc-file-silver" +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 20Gi diff --git a/cs-offerings/kube-configs/storage-free.yaml b/cs-offerings/kube-configs/storage-free.yaml index f2e6b5c..64c453d 100644 --- a/cs-offerings/kube-configs/storage-free.yaml +++ b/cs-offerings/kube-configs/storage-free.yaml @@ -30,6 +30,22 @@ spec: hostPath: path: "/composer" +--- +kind: PersistentVolume +apiVersion: v1 +metadata: + name: ledger-pv + labels: + type: local + name: ledger +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteMany + hostPath: + path: "/ledger" + --- kind: PersistentVolumeClaim apiVersion: v1 @@ -44,6 +60,7 @@ spec: selector: matchLabels: name: shared + --- kind: PersistentVolumeClaim apiVersion: v1 @@ -58,3 +75,18 @@ spec: selector: matchLabels: name: composer + +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: ledger-pvc +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi + selector: + matchLabels: + name: ledger diff --git a/cs-offerings/kube-configs/storage-paid.yaml b/cs-offerings/kube-configs/storage-paid.yaml index 169268c..9581b88 100644 --- a/cs-offerings/kube-configs/storage-paid.yaml +++ b/cs-offerings/kube-configs/storage-paid.yaml @@ -31,3 +31,20 @@ spec: resources: requests: storage: 20Gi + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ledger-pvc + annotations: + #ibmc-file-bronze: 2 IOPS per GB. + #ibmc-file-silver: 4 IOPS per GB. + #ibmc-file-gold: 10 IOPS per GB. + volume.beta.kubernetes.io/storage-class: "ibmc-file-silver" +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 20Gi diff --git a/cs-offerings/kube-configs/wipe_shared.yaml b/cs-offerings/kube-configs/wipe_shared.yaml index 6c086b9..cb535f0 100644 --- a/cs-offerings/kube-configs/wipe_shared.yaml +++ b/cs-offerings/kube-configs/wipe_shared.yaml @@ -12,14 +12,18 @@ spec: - name: shared persistentVolumeClaim: claimName: shared-pvc - + - name: ledger + persistentVolumeClaim: + claimName: ledger-pvc containers: - name: wipeshared image: ibmblockchain/fabric-tools:1.0.3 imagePullPolicy: Always - command: ["sh", "-c", "rm -rf /shared/* /home/*"] + command: ["sh", "-c", "rm -rf /shared/* /home/* /ledger/*"] volumeMounts: - name: composer-card-store mountPath: /home - - mountPath: /shared - name: shared \ No newline at end of file + - name: shared + mountPath: /shared + - name: ledger + mountPath: /ledger \ No newline at end of file diff --git a/cs-offerings/kube-configs/wipe_shared_couchdb.yaml b/cs-offerings/kube-configs/wipe_shared_couchdb.yaml new file mode 100644 index 0000000..3bf5c59 --- /dev/null +++ b/cs-offerings/kube-configs/wipe_shared_couchdb.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: v1 +kind: Pod +metadata: + name: wipeshared-couchdb +spec: + restartPolicy: "Never" + volumes: + - name: couchdb1 + persistentVolumeClaim: + claimName: couchdb1-pvc + - name: couchdb2 + persistentVolumeClaim: + claimName: couchdb2-pvc + containers: + - name: wipeshared-couchdb + image: ibmblockchain/fabric-tools:1.0.3 + imagePullPolicy: Always + command: ["sh", "-c", "rm -rf /couchdb1/* /couchdb2/*"] + volumeMounts: + - name: couchdb1 + mountPath: /couchdb1 + - name: couchdb2 + mountPath: /couchdb2 diff --git a/cs-offerings/scripts/create/create_storage.sh b/cs-offerings/scripts/create/create_storage.sh index b443043..c444705 100755 --- a/cs-offerings/scripts/create/create_storage.sh +++ b/cs-offerings/scripts/create/create_storage.sh @@ -9,10 +9,15 @@ else fi PAID=false +WITH_COUCHDB=false Parse_Arguments() { while [ $# -gt 0 ]; do case $1 in + --with-couchdb) + echo "Configured to setup network with couchdb" + WITH_COUCHDB=true + ;; --paid) echo "Configured to setup a paid storage on ibm-cs" PAID=true @@ -32,9 +37,9 @@ fi echo "Creating Persistent Volumes" if [ "${PAID}" == "true" ]; then - if [ "$(kubectl get pvc | grep shared-pvc | awk '{ print $2 }')" != "Bound" ] || [ "$(kubectl get pvc | grep composer-pvc | awk '{ print $2 }')" != "Bound" ]; then + if [ "$(kubectl get pvc | grep shared-pvc | awk '{ print $2 }')" != "Bound" ] || [ "$(kubectl get pvc | grep composer-pvc | awk '{ print $2 }')" != "Bound" ] || [ "$(kubectl get pvc | grep ledger-pvc | awk '{ print $2 }')" != "Bound" ]; then echo "The paid PVC does not seem to exist" - echo "Creating PVC named shared-pvc and composer-pvc" + echo "Creating PVC named shared-pvc, composer-pvc and ledger-pvc" # making a PVC on ibm-cs paid version echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/storage-paid.yaml" @@ -52,10 +57,43 @@ if [ "${PAID}" == "true" ]; then echo "Waiting for composer-pvc to be bound" sleep 5 done + + while [ "$(kubectl get pvc | grep ledger-pvc | awk '{print $2 }')" != "Bound" ]; + do + echo "Waiting for ledger-pvc to be bound" + sleep 5 + done else - echo "The PVC with name shared-pvc or composer-pvc exists, not creating again" + echo "The PVC with name shared-pvc or composer-pvc or ledger-pvc exists, not creating again" #echo "Note: This can be a normal storage and not a ibm-cs storage, please check for more details" fi + + if [ "${WITH_COUCHDB}" == "true" ]; then + echo "Couchdb is enabled creating storage for couchdb" + if [ "$(kubectl get pvc | grep couchdb1-pvc | awk '{ print $2 }')" != "Bound" ] || [ "$(kubectl get pvc | grep couchdb2-pvc | awk '{ print $2 }')" != "Bound" ]; then + echo "The paid PVC for couchdb does not seem to exist" + echo "Creating PVC named couchdb1 and couchdb2" + fi + + # making a PVC on ibm-cs paid version + echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/storage-couchdb-paid.yaml" + kubectl create -f ${KUBECONFIG_FOLDER}/storage-couchdb-paid.yaml + sleep 5 + + while [ "$(kubectl get pvc | grep couchdb1-pvc | awk '{print $2 }')" != "Bound" ]; + do + echo "Waiting for couchdb1-pvc to be bound" + sleep 5 + done + + while [ "$(kubectl get pvc | grep couchdb2-pvc | awk '{print $2 }')" != "Bound" ]; + do + echo "Waiting for couchdb2-pvc to be bound" + sleep 5 + done + else + echo "The PVC with name couchdb1-pvc or couchdb2-pvc exists, not creating again" + fi else if [ "$(kubectl get pvc | grep shared-pvc | awk '{print $2}')" != "Bound" ]; then echo "The Persistant Volume does not seem to exist or is not bound" @@ -74,5 +112,30 @@ else echo "The Persistant Volume exists, not creating again" fi + if [ "${WITH_COUCHDB}" == "true" ]; then + echo "Couchdb is enabled creating storage for couchdb" + if [ "$(kubectl get pvc | grep couchdb1-pvc | awk '{ print $2 }')" != "Bound" ] || [ "$(kubectl get pvc | grep couchdb2-pvc | awk '{ print $2 }')" != "Bound" ]; then + echo "The PVC for couchdb does not seem to exist or is not bound" + echo "Creating PVC named couchdb1 and couchdb2" + + echo "Running: kubectl create -f ${KUBECONFIG_FOLDER}/storage-couchdb-free.yaml" + kubectl create -f ${KUBECONFIG_FOLDER}/storage-couchdb-free.yaml + sleep 5 + + while [ "$(kubectl get pvc | grep couchdb1-pvc | awk '{print $2 }')" != "Bound" ]; + do + echo "Waiting for couchdb1-pvc to be bound" + sleep 5 + done + + while [ "$(kubectl get pvc | grep couchdb2-pvc | awk '{print $2 }')" != "Bound" ]; + do + echo "Waiting for couchdb2-pvc to be bound" + sleep 5 + done + else + echo "The PVC with name couchdb1-pvc or couchdb2-pvc exists, not creating again" + fi + fi fi diff --git a/cs-offerings/scripts/delete/delete_storage.sh b/cs-offerings/scripts/delete/delete_storage.sh index dd35bb5..c5f7201 100755 --- a/cs-offerings/scripts/delete/delete_storage.sh +++ b/cs-offerings/scripts/delete/delete_storage.sh @@ -38,6 +38,9 @@ if [ "${DELETE_VOLUMES}" == "true" ]; then echo "Deleting Persistant Storage" echo "Running: kubectl delete -f ${KUBECONFIG_FOLDER}/storage-${OFFERING}.yaml" kubectl delete -f ${KUBECONFIG_FOLDER}/storage-${OFFERING}.yaml + + echo "Running kubectl delete -f ${KUBECONFIG_FOLDER}/storage-couchdb-${OFFERING}.yaml" + kubectl delete -f ${KUBECONFIG_FOLDER}/storage-couchdb-${OFFERING}.yaml else echo "-i | --include-volumes not included in the command, will not delete storage/volumes." fi \ No newline at end of file diff --git a/cs-offerings/scripts/delete_all.sh b/cs-offerings/scripts/delete_all.sh index b88aa9f..762400e 100755 --- a/cs-offerings/scripts/delete_all.sh +++ b/cs-offerings/scripts/delete_all.sh @@ -34,6 +34,7 @@ echo "=> DELETE_ALL: Deleting instantiate chaincode pod" echo "" echo "=> DELETE_ALL: Wiping the shared folder empty" ./wipe_shared.sh +./wipe_shared_couchdb.sh echo "" echo "=> DELETE_ALL: Deleting persistent volume - call." diff --git a/cs-offerings/scripts/wipe_shared.sh b/cs-offerings/scripts/wipe_shared.sh index 9d00b49..2080807 100755 --- a/cs-offerings/scripts/wipe_shared.sh +++ b/cs-offerings/scripts/wipe_shared.sh @@ -2,7 +2,7 @@ # cp ../kube-configs/wipe_shared.yaml.base ../kube-configs/wipe_shared.yaml -if [ "$(kubectl get pvc | grep shared-pvc | wc -l | awk '{print $1}')" == "0" ] || [ "$(kubectl get pvc | grep composer-pvc | wc -l | awk '{print $1}')" == "0" ]; then +if [ "$(kubectl get pvc | grep shared-pvc | wc -l | awk '{print $1}')" == "0" ] || [ "$(kubectl get pvc | grep composer-pvc | wc -l | awk '{print $1}')" == "0" ] || [ "$(kubectl get pvc | grep ledger-pvc | wc -l | awk '{print $1}')" == "0" ]; then echo "Error Persistent Volumes does not exist.. Cannot run wipeshared" exit 1 else diff --git a/cs-offerings/scripts/wipe_shared_couchdb.sh b/cs-offerings/scripts/wipe_shared_couchdb.sh new file mode 100755 index 0000000..dce5a37 --- /dev/null +++ b/cs-offerings/scripts/wipe_shared_couchdb.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# cp ../kube-configs/wipe_shared.yaml.base ../kube-configs/wipe_shared.yaml + +if [ "$(kubectl get pvc | grep couchdb1-pvc | wc -l | awk '{print $1}')" == "0" ] || [ "$(kubectl get pvc | grep couchdb2-pvc | wc -l | awk '{print $1}')" == "0" ]; then + echo "Error Persistent Volumes does not exist.. Cannot run wipeshared" + exit 1 +else + kubectl create -f ../kube-configs/wipe_shared_couchdb.yaml +fi + +while [ "$(kubectl get pod -a wipeshared-couchdb | grep wipeshared-couchdb | awk '{print $3}')" != "Completed" ]; do + echo "Waiting for the shared folder to be erased" + sleep 1; +done + +kubectl delete -f ../kube-configs/wipe_shared_couchdb.yaml