弹性伸缩式k8s中的一大亮点功能,当负载大的时候,你可以对应用进行扩容,提升pod的副本数来应对大量的流量,当负载小的时候可以对应用进行缩容,以避免资源浪费。也可以让应用自动的进行扩容和缩容,这一功能有用。例如当微博出现了一个话题时,这个时候人们都去访问,此时他的服务器将无法处理大量的流量访问,这个时候就需要扩容,而当这个话题不在新鲜时,人们的访问流量也就是降下来了,那么就需要对服务器进行缩容处理,来自动适应流量需求。通过监控来判断阈值进行弹性伸缩。
一、安装heapster监控
wget http://192.168.18.250/file/docker_heapster_grafana.tar.gz
wget http://192.168.18.250/file/docker_heapster_influxdb.tar.gz
[root@k8s-node2 ~]# wget http://192.168.18.250/file/docker_heapster.tar.gz
二、导入镜像
docker load -i docker_heapster_influxdb.tar.gz
docker load -i docker_heapster_grafana.tar.gz
docker load -i docker_heapster.tar.gz
打标签
[root@k8s-node2 ~]# docker tag docker.io/kubernetes/heapster_grafana:v2.6.0 10.0.0.11:5000/heapster_grafana:v2.6.0
[root@k8s-node2 ~]# docker tag docker.io/kubernetes/heapster_influxdb:v0.5 10.0.0.11:5000/heapster_influxdb:v0.5
[root@k8s-node2 ~]# docker tag docker.io/kubernetes/heapster:canary 10.0.0.11:5000/heapster:canary
三、导入yml
[root@k8s-master monitor]# unzip heapster-influxdb.zip
Archive: heapster-influxdb.zip
inflating: heapster-influxdb/grafana-service.yaml
inflating: heapster-influxdb/heapster-controller.yaml
inflating: heapster-influxdb/heapster-service.yaml
inflating: heapster-influxdb/influxdb-grafana-controller.yaml
inflating: heapster-influxdb/influxdb-service.yaml
修改yaml文件
修改配置文件:
#heapster-controller.yaml
spec:
nodeName: 10.0.0.13
containers:
- name: heapster
image: 10.0.0.11:5000/heapster:canary
imagePullPolicy: IfNotPresent
#influxdb-grafana-controller.yaml
spec:
nodeName: 10.0.0.13
containers:
四、启动
[root@k8s-master heapster-influxdb]# kubectl create -f .
五、验证
六、修改rc配置文件
containers:- name: mywebimage: 10.0.0.11:5000/nginx:1.13ports:- containerPort: 80resources:limits:cpu: 100mrequests:cpu: 100m
创建弹性伸缩功能
kubectl autoscale deploy nginx-deployment --max=8 --min=1 --cpu-percent=5
进行压测
ab -n 1000000 -c 40 http://10.0.0.12:33218/index.html
然后刷新压面就会自动创建了pod。
查看所有的pod
kubectl get pod --all-namespaces
有问题请加博主微信进行沟通!
全部评论