facebook

Contact Us

Best Way To Scale Your Blockchain Application In K8 Using HPA

Calender

6th July 2022

Clock

17 min read

Author
Vishal Yadav

Technical Project Manager

 

Overview

 

Building a scalable Blockchain decentralized application is not an easy task because developing a blockchain-based application needs too many services and applications to deploy on a server. If you want to deploy your blockchain application with high availability system, we need to clarify that our infrastructure is scalable. It is because if there is an increase in traffic on your application, and at the same time, your infrastructure is not ready to serve that mush request. It gives a worse impact on the user experience.

 

Why do we need a scalable infrastructure?

 

Let's suppose there is an increase in traffic on your blockchain application, and at the same time, your cloud infrastructure is not ready to serve that many requests and gives a bad user experience. It affects your overall business because you miss the golden opportunity. Thus, this is the reason we need to create an automated scalable infrastructure for your DApps.

 

How does Horizontal pod Autoscaling work?

 

Today everyone is deploying their application on Kubernetes because it's easy to manage and scalable. But most people don't know how to deploy blockchain applications with automated horizontal pod autoscaling on Kubernetes, which is the trickiest part. Not to worry, we'll let you know how pod autoscaling work when you enable pod autoscaling in your Kubernetes deployment. It simply monitors the application CPU and memory utilization. So, whenever your CPU or memory utilization crosses a threshold (Let's suppose I have set an 85% threshold), our traffic increases on our application. If the utilization limit touches the threshold value, Kubernetes automatically launches another replica pod. Thus this is the way pod scaling works, and that's the beauty of the k8 cluster.

 

Here is the sample deployment file with Horizontal pod auto-scaling, and you can customize this manifest file based on your application.

 

deployment_file.yaml

---

apiVersion: apps/v1

kind: Deployment

metadata:

 namespace: analytics

 name: debug-pod

spec:

 selector:

  matchLabels:

   app.kubernetes.io/name: debug-pod

 replicas: 2

 template:

  metadata:

   labels:

    app.kubernetes.io/name: debug-pod

  spec:

   containers:

   - image: ubuntu:latest

    command:

     - "sleep"

     - "604800"

    imagePullPolicy: Always

    resources:

     requests:

      memory: "1000Mi"

      cpu: "1000m"

     limits:

      memory: "1100Mi"

      cpu: "11000m"

    name: debug-pod

---

apiVersion: autoscaling/v2beta2

kind: HorizontalPodAutoscaler

metadata:

 namespace: analytics

 name: debug-pod

 labels:

  app.kubernetes.io/name: debug-pod

spec:

 scaleTargetRef:

  apiVersion: apps/v1

  kind: Deployment

  name: debug-pod

 minReplicas: 1

 maxReplicas: 4

 metrics:

  - type: Resource

   resource:

    name: cpu

    target:

     type: Utilization

     averageUtilization: 85

  - type: Resource

   resource:

    name: memory

    target:

     type: Utilization

     averageUtilization: 85

 behavior:

  scaleUp:

   stabilizationWindowSeconds: 90

Conclusion

Deploying your application on Kubernetes with Horizontal pod autoscaling is a good practice because I am sure that you always want your application to be highly available and automatically scalable. With fault tolerance, there is another vertical pod autoscaling feature available in Kubernetes. Thus we will talk about VPA in another blog. 

Author Vishal Yadav

Vishal is a highly skilled backend developer with extensive 3+ years experience in developing various blockchain platforms. He has a comprehensive understanding of the technologies and has hands-on expertise in Node.js, Ethereum, Layer 1 and Layer 2 solutions, smart contract development, and databases like MySQL and MongoDB. He has a proven track record of working on a range of blockchain-related projects, including token development, staking, governance, indexes, bridges, NFT, marketplace, ICO/IDO, and more. He is adept at managing trading bots, and developing centralized exchanges, and has a creative mind with excellent analytical skills.

Technical Project Manager

bg bg

What's Trending in Tech

bg

Our Offices

India

INDIA

DG-18-009, Tower B,
Emaar Digital Greens, Sector 61,
Gurugram, Haryana
122011.
Unit- 117-120, First Floor,
Welldone Tech Park,
Sector 48, Sohna road,
Gurugram, Haryana
122018.
USA

USA

30N, Gloud St STR E, Sheridan, Wyoming (USA) - 82801
Singapore

SINGAPORE

10 Anson Road, #13-09, International Plaza Singapore 079903.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.