I am using the kubernetes-client java library for the K8s REST API. I want to explore the resource monitoring feature desctibed here https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
I set the resource for the Pods while creating Deployments like this
// ******************* RESOURCES*********************
Quantity memLimit = new Quantity();
memLimit.setAmount("400");
Map<String, Quantity> memMap = new HashMap<String,Quantity>();
memMap.put("memory", memLimit);
ResourceRequirements resourceRequirements = new ResourceRequirementsBuilder()
.withRequests(memMap)
.build();
// ******************* DEPLOYMENT *********************
Deployment deployment = new DeploymentBuilder()
.withNewMetadata()
.withName("first-deployment")
.endMetadata()
.withNewSpec()
.withReplicas(3)
.withNewTemplate()
.withNewMetadata()
.addToLabels(namespaceID, "hello-world-example")
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName("nginx-one")
.withImage("nginx")
.addNewPort()
.withContainerPort(80)
.endPort()
.withResources(resourceRequirements)
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();
deployment = client.extensions().deployments().inNamespace(namespace).create(deployment);
How do I now know, how much memory is being used out of the alocated memory for pods? The documentation says its part of the pod status , but pod status is of the form
(conditions=
[PodCondition
(lastProbeTime=null, lastTransitionTime=2018-01-09T15:53:28Z,
message=null, reason=null,
status=True, type=PodScheduled,
additionalProperties={})],
containerStatuses=[], hostIP=null,
initContainerStatuses=[],
message=null, phase=Pending, podIP=null,
qosClass=Burstable, reason=null,
startTime=null, additionalProperties={})
And the container status
(containerID=null, image=nginx,
imageID=, lastState=ContainerState(running=null, terminated=null, waiting=null, additionalProperties={}),
name=nginx-one, ready=false, restartCount=0, state=ContainerState(running=null, terminated=null, waiting=
ContainerStateWaiting(message=null, reason=ContainerCreating, additionalProperties={}), additionalProperties={}),
additionalProperties={})
Is there an example for monitoring resources on Pods?
I know this question is two years old but the answers here don't provide the actual answer to this question.
In order to get your CPU and memory utilization you need to have the kubernetes metrics server installed on your Kubernetes cluster (See also the official Helm chart if you use helm). Once the metrics server is installed, this lets you run kubernetes commands that will report the metrics usage. For example, running
kubectl top pods -A
will sort all of your pods by their CPU utilization, orkubectl top nodes
will list each node's utilization.kubectl describe pods
as well as the Kubernetes dashboard will also report CPU and memory utilization numbers once the metrics server is installed.To answer your specific question about fabric8, once the metrics server is running, you can obtain CPU and memory utilization with the following code: