Each component within the cells can be scaled up or down. Cellery supports auto scaling with Horizontal pod autoscaler, and Zero-scaling. In addition, its possible to scale components of cells and composites manually.
This README includes,
A component can have either Autoscaling policy or zero scaling policy. Based on that, the underneath autoscaler will be determined.
Generally the autoscaling policy has minimum replica count greater than 0, and hence the horizontal pod autoscaler
will be used to scale up and down the components. The zero-scaling has minimum replica count 0
, and hence when the
component did not get any request, the component will be terminated and it will be running back once a request was directed to the component.
If a component has a scaling policy as Autoscaling policy as explained here, the specified component will be scaled with horizontal pod autoscaler.
By default local, and existing kubernetes cluster will not have the metrics server deployed for horizontal pod autoscaler to work. GCP has it by default. Therefore, if you are using local, or existing kubernetes cluster, then you can enable by following below command. This also can be performed by modify setup.
cellery setup modify --hpa=enable
cellery:Component petComponent = {
name: "pet-service",
source: {
image: "docker.io/isurulucky/pet-service"
},
ingresses: {
stock: <cellery:HttpApiIngress>{ port: 9090,
context: "petsvc",
definition: {
resources: [
{
path: "/*",
method: "GET"
}
]
}
}
},
resources: {
limits: {
memory: "128Mi",
cpu: "500m"
}
},
scaling: {
policy: <AutoScalingPolicy> {
minReplicas: 1,
maxReplicas: 10,
metrics: {
cpu: <cellery:Value>{ threshold : "500m" },
memory: <cellery:Percentage> { threshold : 50 }
}
},
override: true
}
};
The above component pet-service
has an autoscaling policy with minimum replica count 1
and maximum replica count 10
.
Further, threshold values for cpu and memory is provided to decide upong scaling decisions. For detailed syntax, refer here.
Once the above component is wrapped into a cell/composite and deployed in Cellery runtime, the build time auto scaling policy will be applied. Often the build time autoscaling policy is not sufficient, and depends on the runtime environment and available resources, the devops may require to re-evaluate the autoscaling policies. Therefore, the exporting policy will be helpful to understand the current autoscaling policy that is applied to the component. This can be performed as shown below.
For a cell:
cellery export-policy autoscale cell pet-be-instance -f pet-be-policy.yaml
For a composite:
cellery export-policy autoscale composite pet-be-instance -f pet-be-policy.yaml
This will result in a yaml structured file similar to the following:
components:
- name: controller
scalingPolicy:
hpa:
minReplicas: 1
maxReplicas: 5
metrics:
- resource:
name: memory
targetAverageValue: "64Mi"
type: Resource
- name: catalog
scalingPolicy:
replicas: 1
- name: orders
scalingPolicy:
replicas: 1
- name: customers
scalingPolicy:
hpa:
minReplicas: 1
maxReplicas: 3
metrics:
- resource:
name: cpu
targetAverageUtilization: 50
type: Resource
gateway:
scalingPolicy:
replicas: 1
In this exported autoscale policy, the components controller
and customers
have autoscaling policies defined.
For the components catalog
and orders
do not have autoscaling policies, but only the replica count defined.
The gateway also has a flat scaling policy.
These autoscaling policies and fixed replica counts can be modified and re-applied using the Apply Policy command, which will get reflected in the running instances.
Once the policy is exported, the policy can be evaluated, and modified based on the requirement. The
modified policy can be applied to the running cell instance. Note, if the component is defined with scaling policy with
override
parameter false
as shown syntax, the policy cannot be applied in the runtime.
For a cell:
cellery apply-policy autoscale cell petfe pet-fe-modified.yaml
For a composite:
cellery apply-policy autoscale composite petfe pet-fe-modified.yaml
Zero scaling is powered by Knative. The zero-scaling have minimum replica count 0, and hence when the component did not get any request, the component will be terminated and it will be running back once a request was directed to the component.
By default, the cellery installations have zero-scaling disabled. Therefore, if you want to zero scale your components, you have to enable zero-scaling as shown below.
cellery setup modify --scale-to-zero=enable
cellery:Component petComponent = {
name: "pet-service",
source: {
image: "docker.io/isurulucky/pet-service"
},
ingresses: {
stock: <cellery:HttpApiIngress>{ port: 9090,
context: "petsvc",
definition: {
resources: [
{
path: "/*",
method: "GET"
}
]
}
}
},
scaling: {
policy: <ZeroScalingPolicy> {
maxReplicas: 10,
concurrencyTarget: 50
}
}
};
The above component pet-service
has a zero scaling policy (minimum replica count 0
) with maximum replica count 10
.
Further, scaling with be performed based on concurrent requests for the component, and pet-service
has concurrency threshold 50
.
For detailed syntax, refer here.
Just build and run the cell with this scaling configuration for the component, to try out the zero scaling functionality.
Cell and composite components can be scaled up/down manually. This is particularly useful if there is no autoscaling policy attached for a component.
First, export the scale policies for the given cell. Now, modify the exported policy by changing scalingPolicy.replicas
under the selected component:
components:
- name: catalog
scalingPolicy:
replicas: 4
- name: orders
scalingPolicy:
replicas: 1
gateway:
scalingPolicy:
replicas: 2
In the exported scale policy shown above, replicas for catalog
component is set to 4 and for gateway its 2.
Apply the scale policy again so that the changes are reflected.
#What's Next?
- Developing and runing a Cell - step by step explanation on how you could define your own cells.
- How to code cells? - explains how Cellery cells are written.
- Cell patching and advanced deployments - patch components of running instance and create advanced deployments.
- Observe cells - provides the runtime insight of cells and components.