Spring Boot Fullstack Blockchain Application With Hyperledger Fabric running on Kubernetes (Part 2) — Kubernetes Cluster Setup
Hello everyone, through this article series we will the Hyperledger Fabric integration with Spring Boot.In this article, we will look into Kubernetes Cluster, Haproxy,Nfs server introductions and installations using Vagrant.
Other articles on Hyperledger Fabric integration with Spring Boot can be accessed from the links below.
Part 2 — Kubernetes Cluster Setup
Part 4 — Generating Certificates and Artifacts
What is Kubernetes?
Kubernetes is a production-grade open-source container orchestration tool developed by Google to help you manage the containerized/dockerized applications supporting multiple deployment environments like On-premise, cloud, or virtual machines.
The name Kubernetes originates from Greek, meaning helmsman or pilot. K8s as an abbreviation results from counting the eight letters between the “K” and the “s”. Google open-sourced the Kubernetes project in 2014.
Project details of Kubernetes can be accessed via this link
What is Vagrant?
Vagrant is a tool that allows us to create and manage virtual machines developed by HashiCorp. With Vagrant, we can easily configure the virtual machine and manage many machines easily.
Vagrant automates the infrastructure of your virtual machines by using a single file Vagrantfile
.
Project details of Vagrant can be accessed via this link
Vagrant Installation
For vagrant installation, virtualbox or hyperv must be installed on your local computer.We’ll be using the VirtualBox provider, which is the default provider for Vagrant.The Vagranfile I created supports hyperv and virtualbox providers.
You can download Vagrant from https://www.vagrantup.com/ and VirtualBox from https://www.virtualbox.org/wiki/Downloads and install .
After installing you can confirm the vagrant version with installation.
Installing the Guest Addition Plugin for Vagrant
Guest Addition is essentially for being able to unleash Vagrant’s full potential, meaning it is important that it is installed and kept updated. However, ensuring your Vagrant boxes are always running the latest version of Guest Additions can be a time-consuming task, stealing away crucial cycles that could be put to better use.
We can install this plugin with the following command.
vagrant plugin install vagrant-vbguest
Vagrantfile
Vagrantfile is a file in which the necessary information (ram, cpu, vm_provider) is written for configuring and orchestrating virtual machines. Ruby language is used to make this configuration.
Virtual Machine Installations Using Vagrant
Let’s open the project we downloaded from this link and go to the directory where the Vagrantfile is located.
$ cd deploy
We will set up 3 virtual machines for nfs server, ha proxy and kubernetes cluster using vagrant.
The hardware requirements and ips of the virtual machine are shown in the table below.
Vagrant distribution of the Asset Transfer application, a minimum of 10 GB of RAM and 8 core CPU are required.
The BOX_BASE variable in the Vagrantfile specifies the operating system of the vms. For Ubuntu Server 20.04 LTS, the value of this variable is ubuntu/focal64.
BOX_BASE = “ubuntu/focal64”
The NODES variable in the Vagrantfile sets the vms list and their paramaters(ram,cpu,ip,hostname). The type parameter can be haproxy, nfs, and k8s.Kubernetes cluster is currently setting up a single node.If the Kubernetes cluster is desired to consist of multiple master and worker nodes, this NODES variable can be assigned as follows.
For 3 Master,3 Worker Node Setup
Vagrantfile supports multiple master and worker mode installation. It also supports virtualbox and hyperv as virtual machine provider.
2. Now lets create virtual machines.
$ vagrant up
After the Vagrant installation is completed, that is, the virtual machines are created and the configurations we have specified in the Vagrantfile are made, we can connect to the virtual machine we have installed with the vagrant ssh command.
Dynamic NFS Provisioning in Kubernetes
Kubernetes containerized storage allows people to develop data containers on-demand. The confidentiality of the data contained is maintained by providing automatic provisioning.
The storage method is at sky-high demand sprawling out far and wide among various verticals. Numerous applications are coming up for providing contented access to people.
One of the ways Kubernetes allow applications to access storage is the standard Network File Service (NFS) protocol.
NFS Server Installation Using Vagrant
Let’s connect to the nfs server virtual machine with the vagrant ssh command.
$ vagrant ssh nfsserver
Let’s go to the directory where the nfs server installation scripts are located.This directory is the same as the deploy/setup/nfs-server-setup folder in the project. With Vagrant, this directory is synchronized to the virtual machine.
$ cd /vagrant/setup/nfs-server-setup
Let’s give the permission to execute.
$ sudo chmod u+x *.sh
Let’s install Nfs Server.
$ sudo ./install_nfs.sh
After the nfs server installation is complete, let’s run the script that creates the necessary directories for fabric files.
$ ./create_fabric_dir.sh
After the directories are created, let’s copy the fabric files to these directories.
$ ./copy_fabricfiles.sh
The nfs server path is set to /srv/kubedata by default. If you want to change this path, you need to change the NFS_PATH variable in install_nfs.sh, NFS_DIR variable in copy_fabricfiles.sh and NFS_DIR variable in create_fabric_dir.sh.In the project, these scripts are in the deploy/setup/nfs-server-setup folder.
Fabric dosyaları srv/kubedata/fabricfiles patihne kopyalanmıştır.Aşağı komut ile kontrol edelim.
$ ls /srv/kubedata/fabricfiles/
Nfs server installation completed successfully. Let’s exit the terminal of the virtual machine.
$ exit
External Load Balancer in Kubernetes
HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions.
We will use HAProxy as a Kubernetes external loadbalancer. Requests to haproxy from port 80 will be balanced to the nginx ingress controller on the worker nodes.In addition, requests to haproxy from port 6443 will be balanced between kubernetes master nodes.
HAProxy Installation Using Vagrant
Let’s connect to the haproxy virtual machine with the vagrant ssh command.
$ vagrant ssh haproxy
Let’s go to the directory where the haproxy installation scripts are located.This directory is the same as the deploy/setup/haproxy-setup folder in the project. With Vagrant, this directory is synchronized to the virtual machine.
$ cd /vagrant/setup/haproxy-setup
Let’s give the permission to execute.
$ sudo chmod u+x *.sh
Let’s install haproxy
$ sudo ./install_haproxy.sh
Haproxy installation completed successfully. Let’s exit the terminal of the virtual machine.
$ exit
Kubernetes Installation Using Vagrant
We will install a bare metal kubernetes cluster using Kubespray.Kubespray is a composition of Ansible playbooks, inventory, provisioning tools, and domain knowledge for generic OS/Kubernetes clusters configuration management tasks.
Let’s connect to the kubernetes master node virtual machine with the vagrant ssh command.
$ vagrant ssh k8smaster
Let’s go to the directory where the kubernetes installation scripts are located.This directory is the same as the deploy/setup/kubernetes-setup folder in the project. With Vagrant, this directory is synchronized to the virtual machine.
$ cd /vagrant/setup/kubernetes-setup
Let’s give the permission to execute.
$ sudo chmod u+x *.sh
By default, kubernetes is installed with metallb, metric server,helm,weavenet,nfs provisioner,cert manager option.If you want to change this option, you need to change the variables(METALLB_ENABLED,METRIC_SERVER_ENABLED,etc) in install_kubespray.sh and the variables(CERT_MANAGER_ENABLED,ISTIO_ENABLED,etc) in install-prereqs.sh.In the project, these scripts are in the deploy/setup/kubernetes-setup folder.
What is MetalLB?
MetalLB is a load-balancer implementation for bare metal Kubernetes clusters, using standard routing protocols.It is installed by default.
What is Helm?
Helm is a tool for managing Charts. Charts are packages of pre-configured Kubernetes resources.It is installed by default.
What is Nginx Ingress Controller?
Ingress Nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer.It is installed by default.
What is Istio?
Istio, the most popular service mesh implementation, was developed on top of Kubernetes and has a different niche in the cloud native application ecosystem than Kubernetes.It is not installed by default.If you want to change this option, you need to change the ISTIO_ENABLED variable in install-prereqs.sh.
Let’s install kubernetes
$ ./install-prereqs.sh
Kubernetes installation completed successfully. Finally, let’s add the kubernetes cluster to Lens IDE.
What is Lens?
Lens — The Kubernetes IDE (“Lens IDE”) is a distribution of the OpenLens repository with Team Lens specific customizations released under a traditional EULA.
Lens IDE provides the full situational awareness for everything that runs in Kubernetes. It’s lowering the barrier of entry for people just getting started and radically improving productivity for people with more experience.
Lens IDE a standalone application for MacOS, Windows and Linux operating systems. You can download it free of charge for Windows, MacOS, and Linux from Lens IDE website.
Add Kubernetes Cluster to Lens IDE
Let’s copy the contents of the kubectl configuration file.The default kubectl configuration file is located at ~/. kube/config and is referred to as the kubeconfig file.
$ cat ${HOME}/.kube/config
Let’s open the Lens IDE, let’s go to Clusters from the catalog. Let’s choose Add from kubeconfig.
Let’s paste the contents of the kubectl configuration file into the window that opens.Let’s replace https://elb.kub:6443 with https://192.168.12.10:6443. Finally, click Add Cluster.
Kubernetes Cluster has been added successfully.let’s go to Clusters from the catalog. Let’s select kubernetes-admin@cluster.local and click connect.
Kubernetes successfully connected to the cluster. When we select Storage Class under Storage, there is a storage class called nfs-client.
My article ends here. In general,I explained introduction and installation of kubernetes cluster and kubernetes tools, nfs server and haproxy using vagrant.
See you in the next articles.
Project Links
Spring Boot Hlf Starter Project details and installation can be accessed via this link.
Asset Transfer Project details and installation can be accessed via this link