Scale Commerce Services
Two V2 Jenkins jobs change how many replicas of your Self-Managed Commerce services run. They do not run Terraform, so you can use them without reconfiguring the environment.
v2-set-commerce-service-replicassets the number of replicas of one Commerce service. For example, use it to start more Cortex replicas before a large traffic event.v2-stop-start-commerce-environmentstops every service in an environment. You can later run it to start the services again, each with the replica count it had before.
Both jobs change Kubernetes directly. The changes last until the Terraform configuration is reapplied. For details, see How Long the Changes Last.
Set the Replicas of a Service
Use the v2-set-commerce-service-replicas job to set the number of replicas of one service in an environment. You can also set a service to 0 to turn it off.
Services supported by the job:
cortexsearchintegration
If a service has horizontal pod auto-scaling enabled then the specified number of replicas becomes the new minimum number of replicas. If the service does not have horizontal pod auto-scaling enabled then the service is set to use exactly the specified number of replicas.
When increasing replicas
When increasing the number of replicas the job will wait until the new replicas are ready. If the cluster does not have room for the new replicas, the Cluster Autoscaler adds nodes. Adding nodes makes the job take longer.
Zero
It is possible to scale the specified service to zero replicas. If you do so and the service has pod auto-scaling enabled, the service will still stay at zero - auto-scaling is effectively disabled.
Before it scales a service to zero, the job saves the current replica count in the smc.elasticpath.com/original-replicas annotation on the Deployment.
To turn the service back on, run the job again with your desired replica count.
v2-set-commerce-service-replicas Job Parameters
kubernetesNickname
The Kubernetes namespace of the environment. Use the value you gave kubernetesNickname when you configured the environment.
service
The service to change: cortex, search, or integration. The value search changes the search follower (search-slave).
replicaCount
A whole number from 0 to 100. The job rejects any other value and changes nothing.
cloudOpsForKubernetesBranch
The CloudOps for Kubernetes Git reference, such as a branch, tag, or commit hash, to use when cloning the Jenkinsfile that defines how the job runs.
Example: Prepare Cortex for a Traffic Event
-
Run the job with
serviceset tocortexandreplicaCountset to20. -
Check the result:
kubectl get deploy,hpa -n <kubernetesNickname>The Cortex Deployment shows
20/20, and the minimum of the Horizontal Pod Autoscaler (HPA) is20. The HPA maximum is at least20. -
After the event, run the job again with the number you used before, for example
2. The HPA minimum drops, and the extra replicas go away gradually as load drops.
The job never lowers the HPA maximum. To lower it, set autoscaling.maxReplicas for the service in the commerce-values.yaml file of the environment, and run v2-configure-commerce-environment.
Stop and Start an Environment
Use the v2-stop-start-commerce-environment job to stop all services in an environment, and to start them again later. For example, to stop an environment while nobody is using it.
How It Works
Stopping the Environment
When you run the job with scaleAction set to down, it scales services to zero in this order:
- The Self-Managed Commerce application services.
- ActiveMQ.
- The MySQL container, if the environment has one.
The Commerce services are the Self-Managed Commerce Deployments that exist in the specified namespace. The job scales them one at a time and waits for each one to stop.
Before it scales a Deployment to zero, the job saves its replica count in the smc.elasticpath.com/original-replicas annotation. This allows the job to restore the deployment to the right number of replicas when you later run the job to start the environment back up.
Starting the Environment
When you run the job with scaleAction set to up, it starts services in the reverse order:
- The MySQL container, if the environment has one.
- ActiveMQ.
- The Self-Managed Commerce application services.
The job scales each Deployment back to the count in its annotation, and then removes the annotation. A Deployment that is at zero with no saved count starts with one replica. The job skips a Deployment that is already running.
The job waits until MySQL and ActiveMQ are ready before it starts the next stage. After it starts the Commerce services, it waits for the search leader to be ready before starting the other Commerce application services. It does not wait for every Commerce service.
If MySQL or ActiveMQ is not ready after 15 minutes, the job fails and the Commerce services stay stopped. The saved counts remain. Fix the cause, and run the job with up again.
While the Environment Is Stopped
Users who open the environment's addresses get the generic 503 page from the ingress.
What the Job Does Not Change
- Databases outside the cluster, such as Amazon Aurora, Amazon RDS, or an existing database server. If the environment has no MySQL container, the MySQL stage finds nothing to scale and does nothing.
- The nodes in the cluster. The job changes Deployments only.
- The HPAs. An HPA does not scale a Deployment that is at zero.
- The volumes. The job does not delete or modify the environment's Amazon Elastic File System (EFS) and Amazon Elastic Block Store (EBS) volumes.
v2-stop-start-commerce-environment Job Parameters
kubernetesNickname for Stop and Start
The Kubernetes namespace of the environment. Use the value you gave kubernetesNickname when you configured the environment.
scaleAction
Choose down to stop the environment, or up to start it. The default is up.
cloudOpsForKubernetesBranch for Stop and Start
The CloudOps for Kubernetes Git reference, such as a branch, tag, or commit hash, to use when cloning the Jenkinsfile that defines how the job runs.
How Long the Changes Last
Both jobs change only Kubernetes. The changes last until the Terraform configuration is reapplied, which happens when you run the deploy-or-delete-commerce-stack or v2-configure-commerce-environment job.
To make a replica count permanent, set replicas for the service in the commerce-values.yaml file of the environment, and run v2-configure-commerce-environment. For the file format, see Environment Specification.