Horizontal Pod Autoscaler - failed to get CPU consumption and request: metrics obtained for 0/2 of pods
Hello everyone!
I created an HPA to scale between 1 and 4 pods of an nginx container.
I'm stressing the service URL with siege tool.
Updating the graphics resource consumption is very slow.
Also, when I run oc get hpa --watch the result takes too long.
In Monitoring tab, I have a lot of messages like:
failed to get CPU utilization: failed to get CPU consumption and request: metrics obtained for 1/2 of pods
failed to get CPU consumption and request: metrics obtained for 0/2 of pods
It seems to me that sometimes the collection of metrics is performed successfully and sometimes an error occurs.
My server has 12 CPUs and 24GB RAM.
Version
$ oc version
oc v1.3.0-rc1
kubernetes v1.3.0+52492b4
features: Basic-Auth GSSAPI Kerberos SPNEGO
Server https://10.8.7.213:8443
openshift v1.3.0-rc1
kubernetes v1.3.0+52492b4
Hi! Whether or not this is actually a problem depends on when you see the messages. If they occur right after you start new pods, then it's just that it takes a few seconds for the first metrics to come in from new pods. Otherwise, you may have issues.
Can you indicate the version of the Heapster pod you are running, and also provide the YAML for the Heapster RC? Depending on how it's configured, you may be hitting time window issues.
@DirectXMan12 - Heapster version 1.1.0
apiVersion: v1
kind: ReplicationController
metadata:
name: heapster
namespace: openshift-infra
selfLink: /api/v1/namespaces/openshift-infra/replicationcontrollers/heapster
uid: c8cd7abd-7b36-11e6-b2f1-005056b90590
resourceVersion: '24215'
generation: 4
creationTimestamp: '2016-09-15T11:23:10Z'
labels:
metrics-infra: heapster
name: heapster
spec:
replicas: 1
selector:
name: heapster
template:
metadata:
creationTimestamp: null
labels:
metrics-infra: heapster
name: heapster
spec:
volumes:
-
name: heapster-secrets
secret:
secretName: heapster-secrets
-
name: hawkular-metrics-certificate
secret:
secretName: hawkular-metrics-certificate
-
name: hawkular-metrics-account
secret:
secretName: hawkular-metrics-account
containers:
-
name: heapster
image: 'openshift/origin-metrics-heapster:latest'
command:
- heapster-wrapper.sh
- '--wrapper.username_file=/hawkular-account/hawkular-metrics.username'
- '--wrapper.password_file=/hawkular-account/hawkular-metrics.password'
- '--wrapper.allowed_users_file=/secrets/heapster.allowed-users'
- '--wrapper.endpoint_check=https://hawkular-metrics:443/hawkular/metrics/status'
- '--source=kubernetes:https://kubernetes.default.svc:443?useServiceAccount=true&kubeletHttps=true&kubeletPort=10250'
- '--sink=hawkular:https://hawkular-metrics:443?tenant=_system&labelToTenant=pod_namespace&labelNodeId=nodename&caCert=/hawkular-cert/hawkular-metrics-ca.certificate&user=%username%&pass=%password%&filter=label(container_name:^system.slice.*|^user.slice)'
- '--tls_cert=/secrets/heapster.cert'
- '--tls_key=/secrets/heapster.key'
- '--tls_client_ca=/secrets/heapster.client-ca'
- '--allowed_users=%allowed_users%'
- '--metric_resolution=20s'
ports:
-
name: http-endpoint
containerPort: 8082
protocol: TCP
resources:
volumeMounts:
-
name: heapster-secrets
mountPath: /secrets
-
name: hawkular-metrics-certificate
mountPath: /hawkular-cert
-
name: hawkular-metrics-account
mountPath: /hawkular-account
readinessProbe:
exec:
command: [/opt/heapster-readiness.sh]
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: heapster
serviceAccount: heapster
securityContext:
status:
replicas: 1
fullyLabeledReplicas: 1
observedGeneration: 4
causes: []
Ok, so, I think the config looks good (I wanted to make sure you didn't have --metric_resolution=10s, which can cause issues due the cAdvisor housekeeping interval also being set to 10s. Your Heapster version looks fine, too. When did you see the error messages about missing metrics? Also can you run heapster at a higher log level (try adding --v=6 of the command array of that config) and seeing if anything looks out of sort in the heapster logs (oc log $NAME_OF_HEAPSTER_CONTAINER)
Improved the memory allocation of the server and now metrics are working fine. Closing this issue.
@Shyckymn Facing the same issue Horizontal Pod Autoscaler - failed to get CPU consumption and request: metrics obtained for 0/2 of pods. -- Could you please provide more info on solution. -- Did you increase the host machine memory or other.
Solution found: set the resources limits of pods as per requirements. If limits are not set, and given some maximum requests then heapster will not capture the utilization as pod won't have a utilization(as set to maximum) resources: limits: memory: 512Mi cpu: 500m requests: memory: 256Mi cpu: 100m
you should only need to set requests, limits should not be necessary for the HPA to function.