Scale your stateless workloads to your evolving container workload requirements.
Before you begin
To complete the tasks in this document, you must request the necessary permissions and prepare your environment.
Request IAM roles
To create, delete, edit, or view stateless workloads in a Kubernetes cluster,
ask your Organization IAM Admin to grant you the Namespace Admin
(namespace-admin) role. This role is bound to your project namespace.
Prepare your environment
To run commands against the pre-configured bare metal Kubernetes cluster, make sure you have the following resources:
Locate the Kubernetes cluster name, or ask your Platform Administrator what the cluster name is.
Sign in and generate the kubeconfig file for the Kubernetes cluster if you don't have one.
Use the kubeconfig path of the Kubernetes cluster to replace
CLUSTER_KUBECONFIGin these instructions.
Scale a deployment
Leverage the scaling functionality of Kubernetes to appropriately scale the amount of pods running in your deployment.
Autoscale the pods of a deployment
Kubernetes offers autoscaling to remove the need of manually updating your deployment when demand evolves. Set the horizontal pod autoscaler in your deployment to enable this feature:
kubectl --kubeconfig CLUSTER_KUBECONFIG \
-n NAMESPACE \
autoscale deployment DEPLOYMENT_NAME \
--cpu-percent=CPU_PERCENT \
--min=MIN_NUMBER_REPLICAS \
--max=MAX_NUMBER_REPLICAS
Replace the following:
CLUSTER_KUBECONFIG: the kubeconfig file for the Kubernetes cluster.NAMESPACE: the project namespace.DEPLOYMENT_NAME: the name of the deployment in which to autoscale.CPU_PERCENT: the target average CPU utilization to request, represented as a percentage, over all the pods.MIN_NUMBER_REPLICAS: the lower limit for the number of pods the autoscaler can provision.MAX_NUMBER_REPLICAS: the upper limit for the number of pods the autoscaler can provision.
To check the current status of the newly-made horizontal pod autoscaler, run:
kubectl get hpa
The output is similar to the following:
NAME REFERENCE TARGET MINPODS MAXPODS REPLICAS AGE
DEPLOYMENT_NAME Deployment/DEPLOYMENT_NAME/scale 0% / 50% 1 10 1 18s
Manually scale the pods of a deployment
If you prefer to manually scale a deployment, run:
kubectl --kubeconfig CLUSTER_KUBECONFIG \
-n NAMESPACE \
scale deployment DEPLOYMENT_NAME \
--replicas NUMBER_OF_REPLICAS
Replace the following:
CLUSTER_KUBECONFIG: the kubeconfig file for the Kubernetes cluster.NAMESPACE: the project namespace.DEPLOYMENT_NAME: the name of the deployment in which to autoscale.DEPLOYMENT_NAME: the chosen number of replicatedPodobjects in the deployment.