

minikube metrics-server HPA 自动扩缩容错误
source link: https://www.cnblogs.com/wangiqngpei557/p/15676674.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

minikube metrics-server pod 错误
启动 minikube addons enable metrics-server
之后查看 metrics-server
pod 会有如下错误
Failed to pull image "k8s.gcr.io/metrics-server-amd64:v0.5.2": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
这个错误是k8s.gcr.io
已经废弃无法访问,需要替换成在国内的镜像,可以使用阿里云的。
registry.cn-hangzhou.aliyuncs.com/google_containers
完整镜像地址。
registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.5.2
进入 minikube docker 手动pull镜像。
minikube ssh
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.5.2
为了让metrics-server-deployment能工作需要手动打个tag并且让pod拉取镜像的规则设置成IfNotPresent。
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.5.2 k8s.gcr.io/metrics-server/metrics-server:v0.5.2
如果不做这一步,也可以手动修改deployment image地址,但是这样比较麻烦。
修改镜像拉取规则
imagePullPolicy: IfNotPresent
手动安装 metrics-server
如果你本地有其他错误,我建议直接关掉minikube metrics-server addons。自行安装metrics-server。
minikube addons disable metrics-server
拉取metrics-server manifast
git://github.com/kubernetes-incubator/metrics-server.git
manifast文件metrics-server/manifests/base/deployment.yaml
(注意,手动安装前还需要像第一节介绍的那样,手动拉取镜像、修改imagePullPolicy模式。)
可能会出现类似 heapster 之类错误。
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
(注意:heapster模式的测量机制在k8s 1.6之后已经不再使用。需要手动打开控制器管理器hpa-rest拉取测量指标。)
但是minikube controller-manager需要在启动的时候设置。
kube-system kube-controller-manager-minikube 1/1 Running 5 2d13h
启动metrics-server测量。
minikube start --extra-config 'controller-manager.horizontal-pod-autoscaler-use-rest-clients=true'
hpa 错误
创建hpa
k autoscale deployment kubia --cpu-percent=30 --min=1 --max=5
查看hpa状态 k get hpa
kubia Deployment/kubia <unknown>/30% 1 5 5 2d12h
查看详情 k describe hpa kubia
the HPA was unable to compute the replica count: failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
其实这里的日志是说已经能正常拉取pod的测量,虽然没有任何返回,但是不影响使用,我们做个测试。
创建一个应用程序。
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubia
labels:
app: kubia
spec:
selector:
matchLabels:
app: kubia
replicas: 3
template:
metadata:
labels:
app: kubia
spec:
containers:
- image: luksa/kubia:v1
name: kubia
resources:
requests:
cpu: 100m
映射一个请求端口。
k expose deployment kubia --port=80 --target-port=8080
监控HPAwatch kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
kubia Deployment/kubia <unknown>/30% 1 5 3 2m34s
kubia 程序默认是3个副本。
在另外一个pod中循环调用应用程序。
k run -it --rm --restart=Never loadgenerator --image=busybox -- sh -c "while true; do wget -O -q http://kubia.default; done"
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
kubia Deployment/kubia 51%/30% 1 5 3 3m53s
hpa生效了,我们看下describe。
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
kubia Deployment/kubia 30%/30% 1 5 5 5m12
HPA-Autoscaler 识别到CPU测量值,已经完成弹性扩容。SuccessfulRescale。
minikube version: v1.16.0
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.9"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0"}
Recommend
-
25
kubernetes的弹性扩缩容HPA部署实施(3) 1、HPA是kubernetes里面pod弹性伸缩的实现,它能根据设置的监控阀值进行pod的弹性扩缩容,目前默认HPA只能支持cpu和内存的阀值检测扩缩容。但hpa不能用于伸缩一些无法进行缩放的控...
-
20
转载请声明出处哦~,本篇文章发布于luozhiyun的博客: https://www.luozhiyun.com ...
-
12
Tuesday, 15 June 2021 12:10 HPA scores distribution deal with Code By Stephen Withers ...
-
7
minikube addons enable ingress 启动错误 开启 minkube ingress 时错误 minikube addons enable ingress --alsologtostderr Verifying ingress addon... 🔎 Verifying ingress addon... I1002 16:59:15.398329...
-
6
Leveraging HPA to auto-scale an app on Kubernetes When you have a predictable pattern in the traffic to your applications, it’s easy for you to scale the infrastructure accordingly. For example, If you are runnin...
-
6
Kubernetes HPA 使用详解-阳明的博客|Kubernetes|Istio|Prometheus|Python|Golang|云原生 Freediver blowing bubble rings in the deep. 在前面的学习中我们使用用一个 kubectl scale 命令可以来实现 Pod...
-
7
Kubernetes的hpa和自定义指标hpa 2021-11-25 8 分钟阅读 kubernetes 的动态伸缩 HPA 是非常有用的特性。 我们的服务器托管在阿里云的 ACK 上,k8s 根据 cpu 或者 内存的使用情况,会自动伸缩关键 pod 的数量,以应对...
-
11
源码分析 kubernetes hpa controller 水平自动扩缩容的实现原理 基于 kubernetes v1.27.0 版本进行 hpa 源码分析.
-
7
Automatically scale your Rails application with HPA
-
13
Istio Sidecar 的资源和性能管理:从监控到自动扩缩容的最佳实践 发布于 2024-01-03 字数 3060 阅读时长 14 分钟 阅读英文版原文
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK