我在 Google Kubernetes Engine 中有一個集群,并希望通過記憶體自動擴展其中一個部署。
進行部署后,我使用以下命令檢查水平擴展
kubectl describe hpa -n my-namespace
有了這個結果:
Name: myapi-api-deployment
Namespace: my-namespace
Labels: <none>
Annotations: <none>
CreationTimestamp: Tue, 15 Feb 2022 12:21:44 0100
Reference: Deployment/myapi-api-deployment
Metrics: ( current / target )
resource memory on pods (as a percentage of request): <unknown> / 50%
Min replicas: 1
Max replicas: 5
Deployment pods: 1 current / 1 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive False FailedGetResourceMetric the HPA was unable to compute the replica count: failed to get memory utilization: missing request for memory
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetResourceMetric 2m22s (x314 over 88m) horizontal-pod-autoscaler failed to get memory utilization: missing request for memory
當我使用該kubectl top命令時,我可以看到記憶體和 cpu 使用情況。這是我的部署,包括自動縮放:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api-deployment
namespace: my-namespace
annotations:
reloader.stakater.com/auto: "true"
spec:
replicas: 1
selector:
matchLabels:
app: my-api
version: v1
template:
metadata:
labels:
app: my-api
version: v1
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
serviceAccountName: my-api-sa
containers:
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:2
imagePullPolicy: Always
args: [
"--listener_port=9000",
"--backend=127.0.0.1:8080",
"--service=myproject.company.ai"
]
ports:
- containerPort: 9000
- name: my-api
image: gcr.io/myproject/my-api:24
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: "/healthcheck"
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: "/healthcheck"
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
resources:
limits:
cpu: 500m
memory: 2048Mi
requests:
cpu: 300m
memory: 1024Mi
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: my-api-deployment
namespace: my-namespace
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-api-deployment
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: memory
target:
type: "Utilization"
averageUtilization: 50
---
使用 GKE 檔案推薦的 autoscaling/v2beta2
uj5u.com熱心網友回復:
將 HPA 與記憶體或 CPU 一起使用時,您需要為 HPA 使用的任何指標設定資源請求。請參閱Horizo??ntalPodAutoscaler 如何作業,特別是
對于每個 Pod 的資源指標(如 CPU),控制器從資源指標 API 中獲取 Horizo??ntalPodAutoscaler 所針對的每個 Pod 的指標。然后,如果設定了目標利用率值,則控制器將利用率值計算為每個 Pod 中容器上的等效資源請求的百分比。如果設定了目標原始值,則直接使用原始度量值。
您的 HPA 設定為與my-api-deployment具有兩個容器的匹配。您為 設定了資源請求,my-api但沒有為esp. 所以你只需要添加一個記憶體資源請求到esp.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/430872.html
標籤:Kubernetes 谷歌云平台 记忆 谷歌 Kubernetes 引擎 帕
