|
| 1 | +--- |
| 2 | +title: Horizontal Scaling Architecture and Features |
| 3 | +linkTitle: Horizontal Scaling |
| 4 | +description: > |
| 5 | + Learn how the Horizontal Scaling feature helps by distributing operations across Armory Scale Agent replicas in your Armory Continuous Deployment or Spinnaker environment. |
| 6 | +aliases: |
| 7 | + - /scale-agent/tasks/horizontal-scaling/ |
| 8 | +--- |
| 9 | + |
| 10 | +## Overview of Horizontal Scaling |
| 11 | + |
| 12 | +Rather than sending operations to the first Scale Agent instance that could handle it, horizontal Scaling provides a way to improve operations by distributing them across all the Scale Agent replicas that could handle it. |
| 13 | + |
| 14 | +### How to enable and use Horizontal Scaling |
| 15 | + |
| 16 | +First, familiarize yourself with the architecture and features in this guide. Then you can: |
| 17 | + |
| 18 | +1. {{< linkWithTitle "plugins/scale-agent/tasks/horizontal-scaling/operations-enable.md" >}} |
| 19 | + |
| 20 | +## Horizontal Scaling glossary |
| 21 | + |
| 22 | +- **K8s Operation**: an abstraction of a K8s operation; Get, List, Add, Delete, Patch etc. |
| 23 | +- **Dynamic account Operation**: an abstraction of a dynamic account operation; Add or Unregister accounts |
| 24 | +- **Endpoint**: the URL segment after the Clouddriver root |
| 25 | +- **Request**: an instruction that isn’t fulfilled immediately and can have different outcomes; a request can be done through HTTP by the admin or internally by one of the services. |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +First is important to understand the main difference between K8s operations and Dynamic account operations. |
| 30 | + |
| 31 | +|K8s |Dynamic account | |
| 32 | +|---------------------------------------------|-------------------------------------------------------| |
| 33 | +|Are handled by a single Scale Agent Instance |Could be handled by more than one Scale Agent Instance | |
| 34 | +|Are processed on every polling cycle |Are processed on demand | |
| 35 | + |
| 36 | + |
| 37 | +The Scale Agent stores K8s and Dynamic Account operations data in dedicated tables that act like a queue: |
| 38 | +- `clouddriver.kubesvc_operation`: Has the information of new received operations |
| 39 | +- `clouddriver.kubesvc_operation_single_assign`: Has the information of K8s operations that could be assigned just to a single Scale Agent Instance |
| 40 | +- `clouddriver.kubesvc_operation_multiple_assign`: Has the information of dynamic account operations that could be assigned to multiple Scale Agent Instances |
| 41 | +- `clouddriver.kubesvc_operation_history`: Has the information of K8s and dynamic account operations responses |
| 42 | + |
| 43 | +### K8s Operations |
| 44 | + |
| 45 | +The Scale Agent Plugin creates a job per Scale Agent Instance registration, this job is in charge of: |
| 46 | +1. Fetching pending K8s operations from `clouddriver.kubesvc_operation` table |
| 47 | +2. Assigning pending K8s operations on clouddriver.kubesvc_operation_single_assign table |
| 48 | +3. Fetch assigned K8s operations from `clouddriver.kubesvc_operation_single_assign` table and send it to Scale Agent |
| 49 | + |
| 50 | +Some important thing to know about it, is that when getting a bad operation response and there is still time to do a retry (based on `kubesvc.cache.operationWaitMs` property), the Scale Agent Plugin does the following: |
| 51 | +The Scale Agent Plugin does: |
| 52 | +1. Stored the response on `clouddriver.kubesvc_operation_history` table |
| 53 | +2. Unassigns the operation from `clouddriver.kubesvc_operation_single_assign` table, so that another or the same Scale Agent instance can take it again |
| 54 | + |
| 55 | +```mermaid |
| 56 | +C4Deployment |
| 57 | + title Scale Agent Horizontal Scaling Registration Jobs |
| 58 | + Boundary(spin, "Armory Continuous Deployment or Spinnaker", "Instance", $borderColor="#0FC2C0") { |
| 59 | + Boundary(cd, "Clouddriver", "Service", $borderColor="orange") { |
| 60 | + System(sap, "Scale Agent Plugin<br/>", "For each registration creates a job to assign and send<br/>every N milliseconds the maximum number of K8s operations.<br/><br/>N = kubesvc.operations.database.scan.initialDelay | maxDelay<br/>maximum number = kubesvc.operations.database.scan.batchSize") |
| 61 | + System(saj0, "Scale Agent Job 0", "") |
| 62 | + System(saj1, "Scale Agent Job 1", "") |
| 63 | + System(saj2, "Scale Agent Job 2", "") |
| 64 | + UpdateElementStyle(saj0, $bgColor="#04AA6D", $borderColor="none") |
| 65 | + UpdateElementStyle(saj1, $bgColor="#f44336", $borderColor="none") |
| 66 | + UpdateElementStyle(saj2, $bgColor="#555555", $borderColor="none") |
| 67 | + } |
| 68 | + Boundary(sa, "Armory Scale Agent", "Service", $borderColor="purple") { |
| 69 | + System(sar0, "Replica 0", "") |
| 70 | + System(sar1, "Replica 1", "") |
| 71 | + System(sar2, "Replica 2", "") |
| 72 | + UpdateElementStyle(sar0, $bgColor="#04AA6D", $borderColor="none") |
| 73 | + UpdateElementStyle(sar1, $bgColor="#f44336", $borderColor="none") |
| 74 | + UpdateElementStyle(sar2, $bgColor="#555555", $borderColor="none") |
| 75 | + } |
| 76 | + Rel(sar0, sap, "Registration", "") |
| 77 | + UpdateRelStyle(sar0, sap, $textColor="black", $lineColor="#04AA6D") |
| 78 | + Rel(sar1, sap, "Registration", "") |
| 79 | + UpdateRelStyle(sar1, sap, $textColor="black", $lineColor="#f44336") |
| 80 | + Rel(sar2, sap, "Registration", "") |
| 81 | + UpdateRelStyle(sar2, sap, $textColor="black", $lineColor="#555555") |
| 82 | + Rel(sap, saj0, "Create") |
| 83 | + UpdateRelStyle(sap, saj0, $textColor="black", $lineColor="#04AA6D") |
| 84 | + Rel(sap, saj1, "Create") |
| 85 | + UpdateRelStyle(sap, saj1, $textColor="black", $lineColor="#f44336", $offsetX="-30", $offsetY="55") |
| 86 | + Rel(sap, saj2, "Create") |
| 87 | + UpdateRelStyle(sap, saj2, $textColor="black", $lineColor="#555555", $offsetX="-60", $offsetY="155") |
| 88 | + BiRel(sar0, saj0, "HandleOp", "request/response") |
| 89 | + UpdateRelStyle(sar0, saj0, $textColor="black", $lineColor="#04AA6D", $offsetX="-100", $offsetY="30") |
| 90 | + BiRel(sar1, saj1, "HandleOp", "request/response") |
| 91 | + UpdateRelStyle(sar1, saj1, $textColor="black", $lineColor="#f44336") |
| 92 | + BiRel(sar2, saj2, "HandleOp", "request/response") |
| 93 | + UpdateRelStyle(sar2, saj2, $textColor="black", $lineColor="#555555") |
| 94 | + } |
| 95 | + UpdateLayoutConfig($c4ShapeInRow="1", $c4BoundaryInRow="2") |
| 96 | +``` |
| 97 | + |
| 98 | +### Dynamic account Operations |
| 99 | + |
| 100 | +Since dynamic account operations requests are less usual, the Scale Agent Plugin flow is as follows: |
| 101 | + |
| 102 | +1. Receive and store the new dynamic account operation on `clouddriver.kubesvc_operation` table |
| 103 | +2. Assign the dynamic account operation on `clouddriver.kubesvc_operation_multiple_assign` table; it could be assigned to all connected Scale Agent instance or to instances with the recived zoneId |
| 104 | +3. Notify to all instances to fetch pending dynamic account operations from `clouddriver.kubesvc_operation_multiple_assign` table |
| 105 | +4. Each instance reads and sends pending dynamic account operations to Scale Agent |
| 106 | +5. Wait and send the response back |
| 107 | + |
| 108 | +```mermaid |
| 109 | +sequenceDiagram |
| 110 | + actor User |
| 111 | + participant Plugin |
| 112 | + participant Service |
| 113 | +
|
| 114 | + User->>Plugin: Send dynamic account operation |
| 115 | + Plugin->>Plugin: Store in clouddriver.kubesvc_operation |
| 116 | + Plugin->>Plugin: Assign on clouddriver.kubesvc_operation_multiple_assign |
| 117 | + Plugin->>Plugin: Notify all to read and send pending operations |
| 118 | + Plugin->>Service: gRPC HandleOp |
| 119 | + Service-->>Plugin: return |
| 120 | + Plugin->>Plugin: Store response in clouddriver.kubesvc_operation_history |
| 121 | + Plugin-->>User: return |
| 122 | +``` |
0 commit comments