背景
HPA显示异常,TARGETS部分显示unknown。
[root@a1 ~]# kubectl get hpa -n istio-system
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
istio-ingressgateway Deployment/istio-ingressgateway 7%/80% 1 5 1 11d
istiod-1-11-2 Deployment/istiod-1-11-2 1%/80% 1 5 1 11d
jaeger-collector Deployment/jaeger-collector <unknown>/90%, <unknown>/90% 1 5 1 11d
分析
HPA,全称为Horizontal Pod Autoscaler,是kubernetes(以下简称k8s)的一种资源对象,能够根据某些指标对在statefulSet、replicaController、replicaSet等集合中的pod数量进行动态伸缩,使运行在上面的服务对指标的变化有一定的自适应能力。
要实现HPA能力,需要满足下面两个条件:
- Kubernetes系统运行了metrics-server,用以下方法检查。如果没有运行,需要安装metrics-server;
# kubectl get pod -A | grep metrics-server
[root@a1 ~]# kubectl get pod -A | grep metrics-server
kube-system metrics-server-6f45b4b8f6-gbhws 1/1 Running 0 11d
- HPA对应的pod,需要设置request资源;
Resources:
requests:
cpu: <this is missing! Add it>
再回到上面的问题,其他的HPA都显示正常,说明满足第一个条件,查看第二个条件,果然是对应的资源没有设置内存和cpu的request,修改后,稍等片刻,HPA即显示正常。
# kubectl get hpa -A
NAMESPACE NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
istio-system istio-ingressgateway Deployment/istio-ingressgateway 6%/80% 1 5 1 11d
istio-system istiod-1-11-2 Deployment/istiod-1-11-2 3%/80% 1 5 1 11d
istio-system jaeger-collector Deployment/jaeger-collector 26%/90%, 10%/90% 1 5 1 11d