Kubernetes "unable to get metrics"



我正试图通过分别运行以下两个命令来自动缩放部署和状态集:

kubectl autoscale statefulset mysql --cpu-percent=50 --min=1 --max=10
kubectl expose deployment frontend --type=LoadBalancer --name=frontend

遗憾的是,在minikube仪表板上,这个错误出现在两个服务下:

failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)

在网上搜索时,我发现可能是dns错误,所以我检查了一下,但CoreDNS似乎运行良好。这两种工作负载都没有什么特别之处,这是"前端"部署:

apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
app: frontend
spec:
replicas: 3
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: hubuser/repo
ports:
- containerPort: 3000

有人有什么建议吗?

首先,请您验证API是否正常工作?为此,请运行kubectl get --raw /apis/metrics.k8s.io/v1beta1

如果你得到一个类似的错误:

"Error from server (NotFound):">

请遵循以下步骤:

1.-从kube-apiserver清单中删除所有代理环境变量。

2.-在kube-controller-manager-amd64中,设置--horizontal-pod-autoscaler-use-rest-clients=false

3.-最后一种情况是默认情况下禁用度量服务器插件。您可以使用进行验证

$minikube插件列表

如果它被禁用,您将看到类似metrics-server: disabled的内容。

您可以使用启用它

$minikube addons enable metrics-server

完成后,删除并重新创建您的HPA。

您可以使用以下线程作为参考。

最新更新