k8s弹性伸缩,需要附加插件heapster

1.安装heapster监控

1:上传并导入镜像,打标签

ls *.tar.gz
for n in `ls *.tar.gz`;do docker load -i $n ;done
docker tag docker.io/kubernetes/heapster_grafana:v2.6.0 10.0.0.11:5000/heapster_grafana:v2.6.0
docker tag  docker.io/kubernetes/heapster_influxdb:v0.5 10.0.0.11:5000/heapster_influxdb:v0.5
docker tag docker.io/kubernetes/heapster:canary 10.0.0.11:5000/heapster:canary

2:上传配置文件,kubectl create -f .

修改配置文件:
#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:

3:打开dashboard验证
k8s 弹性伸缩-LMLPHP

2.弹性伸缩

1:修改rc的配置文件

  containers:
  - name: myweb
    image: 10.0.0.11:5000/nginx:1.13
    ports:
    - containerPort: 80
    resources:
      limits:
        cpu: 100m
      requests:
        cpu: 100m

2:创建弹性伸缩规则

kubectl autoscale deploy nginx-deployment --max=8 --min=1 --cpu-percent=10

3:测试 使用ab命令进行测试

ab -n 1000000 -c 40 http://172.16.28.6/index.html

扩容截图

k8s 弹性伸缩-LMLPHP

缩容:
k8s 弹性伸缩-LMLPHP

05-28 06:38