跳转到内容

CCE 弹性伸缩(HPA / CA)

HPA(HorizontalPodAutoscaler) can increase and decrease pods according to policies.

HPA

When the node resources under the cluster are insufficient or wasted, CA can increase and decrease Node according to the policy.

cluster autoscaler

To use HPA, you need to install an add-on that provides metrics APIs. Select one of the following add-ons based on your cluster version and actual requirements.

Before using the node scaling function, you must install the autoscaler add-on of v1.13.8 or later.

hpa & CA

HPA mechanisim

hpa mechanism

Run a demo deployment(Run and expose php-apache server)

apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
spec:
selector:
matchLabels:
run: php-apache
template:
metadata:
labels:
run: php-apache
spec:
containers:
- name: php-apache
image: registry.k8s.io/hpa-example
ports:
- containerPort: 80
resources:
limits:
cpu: 500m
requests:
cpu: 200m
---
apiVersion: v1
kind: Service
metadata:
name: php-apache
labels:
run: php-apache
spec:
ports:
- port: 80
selector:
run: php-apache

Resource Management for Pods and Containers

create the deployment

终端窗口
kubectl apply -f https://k8s.io/examples/application/php-apache.yaml
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
kubectl get hpa
# Increase the load
kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
kubectl get hpa php-apache --watch
kubectl get deployment php-apache

Install the metrics-server plug-in, and add a loop access test to the corresponding load to mode high concurrent requests.

hpa-demo-test

We can view the expansion and contraction process through the log.

hpa-operator-events

Command operation is difficult for many people, but the graphical interface will be much simpler. CCE supports both command operation and easier click configuration through the web interface.

CCE create HPA

Huaweicloud CCE support customedHPA, we can set more step’s actions.

customedHPA

HorizontalPodAutoscaler Walkthrough

Using HPA and CA for Auto Scaling of Workloads and Nodes

Create a CCE nodepool, update enable the node pool autoscaling.

cluster autoscaling enable

Configure the node scaling rules:

node scaling

Setting CA rules by yaml

Elastic Scaling of CCE Pods to CCI

Auto scaling