如何为HPA自动缩放指标启用KubeAPI服务器 [英] How to Enable KubeAPI server for HPA Autoscaling Metrics

查看:200
本文介绍了如何为HPA自动缩放指标启用KubeAPI服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kube v1.13.0版本.由于Heapster从v1.11开始贬值,因此我一直无法为集群指标启用API服务器来实现HPA.

I am using Kube version v1.13.0. Since Heapster is depreciated from v1.11 I am stuck in enabling the API server for cluster Metrics to implement HPA.

附加的图片以供参考

有人可以指导我逐步启用API Metrics服务器或任何演示视频.进一步进行将非常有帮助.

Can someone guide me for step by step enable for the API Metrics server or any Demo video. It would be really helpful to proceed further.

请让我知道是否需要进一步的信息.

Please let me know if any further information needed.

谢谢 迪娜

推荐答案

我可以使用metrics-server来实现HPA,因为不建议使用heapster.我已按照以下步骤操作:

I am able to implement HPA using metrics-server as heapster is depreciated. I have followed the following steps:

  1. 克隆度量服务器github存储库:git clone https://github.com/kubernetes-incubator/metrics-server.git

进入目录cd deploy/1.8+并运行以下yaml文件:

Go into directory cd deploy/1.8+ and run following yaml files:

[root@ip-10-0-1-91 1.8+]# kubectl apply -f aggregated-metrics-reader.yaml 
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f auth-reader.yaml 
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f auth-delegator.yaml 
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f metrics-apiservice.yaml 
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f resource-reader.yaml 
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f metrics-server-deployment.yaml 
serviceaccount/metrics-server created
deployment.extensions/metrics-server created
[root@ip-10-0-1-91 1.8+]# kubectl apply -f metrics-server-service.yaml 
service/metrics-server created

现在创建要测试自动缩放的Pod(摘自kubernetes官方文档):

Now create a pod you want to test for autoscaling (taken from kubernetes official docs):

[root@ip-10-0-1-91 auto]#  kubectl run --generator=run-pod/v1 php-apache -- 
image=k8s.gcr.io/hpa-example --requests=cpu=200m --expose --port=80
service/php-apache created
deployment.apps/php-apache created

现在创建自动扩展部署:

Now create a autoscale deployment:

[root@ip-10-0-1-91 auto]# kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
horizontalpodautoscaler.autoscaling/php-apache autoscaled

现在检查HPA,您的指标是否达到:

Now check the HPA, your metrics are coming or not:

[root@ip-10-0-1-91 manifests]# kubectl get hpa
NAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   0%/50%    1         10        1          2m

现在使用以下命令从另一个窗口生成负载:

Now generate load from another window using:

kubectl run -i --tty load-generator --image=busybox /bin/sh

它将打开一个sh终端,您可以使用以下命令从该sh终端运行负载:

It will open a sh terminal and you can run a load from that sh terminal using:

while true; do wget -q -O- http://php-apache.default.svc.cluster.local; done

花一分钟左右的时间在您的Pod上承受足够的负载,您会看到一声繁荣:

It will take a minute or so to take enough load on your pod and you see a boom:

[root@ip-10-0-1-91 manifests]# kubectl get hpa
NAME         REFERENCE               TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   120%/50%   1         10        4          7m

和豆荚缩放:

希望这有助于使您的HPA正常工作.

Hope this helps to get your HPA working.

用以下yaml文件替换deploy/1.8+中的metrics-server-deployment.yaml文件:

Replace the metrics-server-deployment.yaml file in deploy/1.8+ with the following yaml file:

 apiVersion: v1
 kind: ServiceAccount
 metadata:
   name: metrics-server
   namespace: kube-system
 ---
 apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
   name: metrics-server
   namespace: kube-system
   labels:
     k8s-app: metrics-server
 spec:
   selector:
     matchLabels:
       k8s-app: metrics-server
   template:
     metadata:
       name: metrics-server
       labels:
         k8s-app: metrics-server
     spec:
       serviceAccountName: metrics-server
       volumes:
       # mount in tmp so we can safely use from-scratch images and/or read-only containers
       - name: tmp-dir
         emptyDir: {}
       containers:
       - command:
         - /metrics-server
         - --metric-resolution=30s
         - --kubelet-insecure-tls
         - --kubelet-preferred-address-types=InternalIP
         name: metrics-server
         image: k8s.gcr.io/metrics-server-amd64:v0.3.1
         imagePullPolicy: Always
         volumeMounts:
         - name: tmp-dir
           mountPath: /tmp

此外,在kubelet.conf中启用--authentication-token-webhook,您将能够获得HPA.

Also, enable the --authentication-token-webhook in kubelet.conf, then you will be able to get the HPA.

您需要在要为其创建HPA的部署文件(在您的情况下为tomcat)中设置以下属性,然后只有HPA才能从部署中获取指标.

You need to set following properties in the deployment file (in your case it is tomcat) for which you are creating HPA, then only your HPA can fetch metrics from your deployment.

resources:
  requests:
    memory: "64Mi"
    cpu: "250m"
  limits:
    memory: "128Mi"
    cpu: "500m"

这篇关于如何为HPA自动缩放指标启用KubeAPI服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆