如何为 HPA 自动缩放指标启用 KubeAPI 服务器 [英] How to Enable KubeAPI server for HPA Autoscaling Metrics
问题描述
我使用的是 Kube 版本 v1.13.0.由于 Heapster 从 v1.11 开始贬值,我一直在为集群指标启用 API 服务器以实现 HPA.
希望这有助于您的 HPA 工作.
将 deploy/1.8+
中的 metrics-server-deployment.yaml
文件替换为以下 yaml 文件:
apiVersion: v1种类:服务账户元数据:名称:指标服务器命名空间:kube-system---apiVersion: 扩展/v1beta1种类:部署元数据:名称:指标服务器命名空间:kube-system标签:k8s-app:指标服务器规格:选择器:匹配标签:k8s-app:指标服务器模板:元数据:名称:指标服务器标签:k8s-app:指标服务器规格:serviceAccountName:指标服务器卷:# 挂载在 tmp 中,以便我们可以安全地使用从头开始的图像和/或只读容器- 名称:tmp-dir空目录:{}容器:- 命令:-/度量服务器- --metric-resolution=30s- --kubelet-insecure-tls- --kubelet-preferred-address-types=内部IP名称:指标服务器图片:k8s.gcr.io/metrics-server-amd64:v0.3.1imagePullPolicy:始终卷挂载:- 名称:tmp-dir挂载路径:/tmp
另外,在kubelet.conf中开启--authentication-token-webhook
,即可获取HPA.
您需要在为其创建 HPA 的部署文件(在您的情况下是 tomcat)中设置以下属性,然后只有您的 HPA 可以从您的部署中获取指标.
资源:要求:内存:64Mi"中央处理器:250m"限制:内存:128Mi"中央处理器:500m"
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.
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.
Thanks Deena
I am able to implement HPA using metrics-server
as heapster is depreciated. I have followed the following steps:
- Clone the metrics-server github repo:
git clone https://github.com/kubernetes-incubator/metrics-server.git
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
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
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
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
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
And pods scaling :
Hope this helps to get your HPA working.
EDIT:
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
Also, enable the --authentication-token-webhook
in kubelet.conf, then you will be able to get the HPA.
EDIT2: 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屋!