**
HPA是kubernetes里面pod弹性伸缩的实现方法,它能根据设置的监控阀值进行pod的弹性缩的,HPA默认只能支持cpu的阀值检测扩缩容,但也可以通过custom
metric api 调用prometheus实现自定义metric
来更加灵活的监控指标实现弹性伸缩。但hpa不能用于伸缩一些无法进行缩放的控制器如DaemonSet。
部署Metric-Server
1.1.部署带有资源请求的Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: damon
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.9.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
resources:
requests:
cpu: "100m"
kubectl expose deployment damon
1.2 创建HPA
kubectl autoscale deployment damon —max=10 —min=1 —cpu-percent=80
1.3 增加cpu负载验证pod是否扩容
watch -n1 ‘kubectl top pod && kubectl get hpa && kubectl get pod’
# 安装压力测试工具WebBench
yum -y install gcc
git clone https://github.com/EZLippi/WebBench.git
cd WebBench
make ; make install
# 压力测试,递增的扩容,并不是一次扩容到最大值
webbench -c 1000 -t 60 http://10.43.77.199/
watch -n1 ‘kubectl get hpa && kubectl top pod && kubectl get pod’