Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to monitor the number of pod-replicas in a Kubernetes cluster over time with StackDriver?

I have added several Horizontal Pod Autoscalers (HPAs) to a Kubernetes cluster. I want to monitor the number of replicas of each pod over time.

Does StackDriver have an option to monitor the number of replicas of each pod over time? When creating a metric I can't find an option that will allow me to do this.

like image 529
MAcabot Avatar asked Apr 15 '19 10:04

MAcabot


People also ask

How do you monitor pods in Kubernetes?

One approach to monitoring all cluster nodes is to create a special kind of Kubernetes pod called DaemonSets. Kubernetes ensures that every node created has a copy of the DaemonSet pod, which virtually enables one deployment to watch each machine in the cluster. As nodes are destroyed, the pod is also terminated.

How many replicas should I have Kubernetes?

In general, if you only have one replica of the application, any abnormal termination of it will result in downtime. In other words, you must have at least two running replicas of the application.

Does Kubernetes have monitoring?

There are two main levels of monitoring in Kubernetes: Cluster monitoring – Keeps track of the health of an entire Kubernetes cluster. Helps you verify if nodes are functioning properly and at the right capacity, how many applications run on a node, and how the cluster as a whole utilizes resources.


1 Answers

I don't think you can count pods, but you can count containers. With a constant number of containers inside the replicated Pods and proper filtering, you'll get what you need.

While in Stackdriver go to Dashboard -> Create dashboard. Select the following settings:

Resource type: GKE Container
Metric: Uptime
Filter: (that's actually up to you, probably some label would work)
Group by: (use this if you want to have several lines on the chart at once)
Aggregator: count

What this does is basically gather all the uptimes of containers in your cluster, filter this data through your criteria, and count how many entries are left. This gives you the number of containers that were up at given time. When a container doesn't exist, there's no entry for it, so the number of entries is lower.

If you have only one container per pod, then that's it. If you have more, just take that into account and divide the values on the chart byt the number of containers per pod.

example config

like image 110
Maciek Avatar answered Nov 03 '22 00:11

Maciek