![](https://larsenclose.com/wp-content/uploads/2024/06/DALL·E-2024-06-25-07.27.04-A-minimalistic-black-and-white-image-representing-Hyperledger-Fabric.-The-design-should-be-clean-and-simple-featuring-abstract-network-graphics-with-.webp)
First things first:
curl -sS https://starship.rs/install.sh | sh # get a starship
eval "$(starship init zsh)" # get on board
![](https://larsenclose.com/wp-content/uploads/2024/06/terminal-starship-1024x585.webp)
mkdir -p workspace/ideal
git init .
git config user.email "[email protected]"
git config user.name "LarsenClose"
ls
![](https://larsenclose.com/wp-content/uploads/2024/06/image.png)
vim setup_hyperledger_fabric.sh
#!/bin/bash
set -e
# Function to check and install kubectl
install_kubectl() {
if ! command -v kubectl &> /dev/null; then
echo "kubectl not found. Installing it now."
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
fi
kubectl version --client
}
# Function to check and install helm
install_helm() {
if ! command -v helm &> /dev/null; then
echo "helm not found. Installing it now."
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
fi
helm version
}
# Function to install Python3 and create virtual environment
install_python_venv() {
sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip
python3 -m venv hyperledger_venv
}
# Function to check and install ansible within venv
install_ansible() {
. hyperledger_venv/bin/activate
pip install --upgrade pip
pip install ansible
pip install kubernetes
ansible --version
}
# Start Minikube
start_minikube() {
minikube start --driver=docker
kubectl config use-context minikube
}
# Create Kubernetes namespace
create_namespace() {
kubectl create namespace oss-hlf-infra
}
# Clone the Hyperledger Fabric Ansible playbooks repository
clone_ansible_fabric() {
if [ ! -d "fabric-ansible-collection" ]; then
git clone https://github.com/hyperledger-labs/fabric-ansible-collection.git
fi
cd fabric-ansible-collection
}
# Build and install the Ansible collection from source
install_ansible_collection() {
. ../hyperledger_venv/bin/activate
ansible-galaxy collection build
ansible-galaxy collection install hyperledger-fabric_ansible_collection-*.tar.gz
}
# Create Kubernetes secret for TLS
create_tls_secret() {
mkdir -p tls
openssl req -x509 -newkey rsa:4096 -keyout tls/tls.key -out tls/tls.crt -days 365 -nodes -subj "/CN=myfabric.local"
kubectl create secret tls myfabric-tls-secret --cert=tls/tls.crt --key=tls/tls.key -n oss-hlf-infra
}
# Create Ansible inventory file
create_inventory_file() {
cat <<EOF > inventory.ini
[all]
localhost ansible_connection=local
[k8s-cluster]
localhost
[hyperledger_fabric]
localhost
EOF
}
# Create Ansible playbook file
create_playbook_file() {
cat <<EOF > install-oss.yml
---
- name: Deploy Hyperledger Fabric Open Source Operator and Custom Resource Definitions
hosts: localhost
vars:
state: present
target: k8s
arch: amd64
namespace: oss-hlf-infra
wait_timeout: 3600
roles:
- hyperledger.fabric_ansible_collection.fabric_operator_crds
- name: Deploy Hyperledger Fabric Open Source Console
hosts: localhost
vars:
state: present
target: k8s
arch: amd64
namespace: oss-hlf-infra
console_name: myfabric-console
console_domain: myfabric.local
console_email: [email protected]
console_default_password: adminpw
console_storage_class: standard
console_tls_secret: myfabric-tls-secret
wait_timeout: 3600
roles:
- hyperledger.fabric_ansible_collection.fabric_console
EOF
}
# Run the Ansible playbook to provision Hyperledger Fabric
run_ansible_playbook() {
. ../hyperledger_venv/bin/activate
ansible-playbook -i inventory.ini install-oss.yml -vvv
}
# Main function to orchestrate the setup
main() {
install_kubectl
install_helm
install_python_venv
. hyperledger_venv/bin/activate
install_ansible
start_minikube
create_namespace
create_tls_secret
clone_ansible_fabric
install_ansible_collection
create_inventory_file
create_playbook_file
run_ansible_playbook
# Check the status of the pods
echo "Checking the status of the pods in the namespace oss-hlf-infra..."
kubectl get pods -n oss-hlf-infra
echo "If there are any issues, you can check the logs of the individual pods using:"
echo "kubectl logs <pod-name> -n oss-hlf-infra"
}
# Execute the main function
main
![](https://larsenclose.com/wp-content/uploads/2024/06/hyperledger-fabric-online-local-1024x186.png)
next:
Multi-tenant cluster-api platform agnostic production ready high-availability