<p>Prometheus (and Thanos or Cortex, usually with some Grafana), is what you are looking for.</p>
<p>You have a Kubernetes (vanilla, OpenShift, ...), then kubelet/cadvisor should already be exposing some metrics, which you may scrape with Prometheus, and visualize in Grafana</p>
<p>See cadvisor docs in GitHub: <a href="https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md" rel="nofollow noreferrer">https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md</a></p>
<p>Sample cadvisor scraping job in prometheus, discovering your nodes/targets integrating with Kubernetes API:</p>
<pre><code>- job_name: cadvisor
  bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  kubernetes_sd_configs:
  - role: node
  metrics_path: /metrics/cadvisor
  relabel_configs:
  - action: replace
    source_labels: [__meta_kubernetes_node_name]
    target_label: kubernetes_node_name
  scheme: https
  scrape_interval: 30s
  scrape_timeout: 10s
  tls_config:
    ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    # if ca won't work, add this:
    # insecure_skip_verify: true
</code></pre>
<p>Grafana dashboards for Prometheus/Cadvisor: <a href="https://grafana.com/grafana/dashboards/?dataSource=prometheus&amp;search=cadvisor" rel="nofollow noreferrer">https://grafana.com/grafana/dashboards/?dataSource=prometheus&amp;search=cadvisor</a></p>
<p>... And, you were asking about CLI ...
I'm not sure I have an answer here.
While scripting directly on top of cadvisor is obviously possible: it could take you some time to figure out what to query. Keeping in mind you would be exclusively working with instantenous values / as opposed to Prometheus, which has functions working with metrics over an interval of time.</p>
<p>If possible, I would still look into Prometheus. And once you have one: this you can query, getting bandwidth consumption per pod, container, ... Even in CLI / there's an API. Maybe writing a kubectl plugin, extending get pods/adm top pods</p>

CC BY-SA 4.0
2023-02-20T19:26:02.053Z
I guess I will try to write my own plugin. Thank you for the suggestion.
iRakic
CC BY-SA 4.0
2024-07-05T00:45:42.483Z
I can only see per interface, not pod
onin
CC BY-SA 4.0
2023-02-09T22:08:02.813Z
2023-02-09T22:22:26.453Z
2023-02-09T22:22:26.453Z
SYN
<p>Kubecost is a good tool to get the overall usage metrics and associated costs, please take a look here <a href="https://blog.kubecost.com/blog/network-egress-traffic-costs/" rel="nofollow noreferrer">https://blog.kubecost.com/blog/network-egress-traffic-costs/</a></p>

CC BY-SA 4.0
2023-02-08T10:14:19.230Z
2023-02-08T10:14:19.230Z
Govind Kailas
<p>Can someone tell me how I can get bandwidth usage per pod in Kubernetes from CLI? Ideally, I need something that will extract bandwidth usage for every pod.</p>

<kubernetes><networking><kubectl><network-monitoring>
Bandwidth utilization by pod on Kubernetes
iRakic
# Bandwidth utilization by pod on Kubernetes

(Asked by: username_0 on 2023-02-07)

Can someone tell me how I can get bandwidth usage per pod in Kubernetes from CLI? Ideally, I need something that will extract bandwidth usage for every pod.

**Tags:** kubernetes, networking, kubectl, network-monitoring


---

## 2 answers

### Answer by username_1 on 2023-02-09. Score: 2

Prometheus (and Thanos or Cortex, usually with some Grafana), is what you are looking for.
You have a Kubernetes (vanilla, OpenShift, ...), then kubelet/cadvisor should already be exposing some metrics, which you may scrape with Prometheus, and visualize in Grafana
See cadvisor docs in GitHub: https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md
Sample cadvisor scraping job in prometheus, discovering your nodes/targets integrating with Kubernetes API:
- job_name: cadvisor
  bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  kubernetes_sd_configs:
  - role: node
  metrics_path: /metrics/cadvisor
  relabel_configs:
  - action: replace
    source_labels: [__meta_kubernetes_node_name]
    target_label: kubernetes_node_name
  scheme: https
  scrape_interval: 30s
  scrape_timeout: 10s
  tls_config:
    ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    # if ca won't work, add this:
    # insecure_skip_verify: true

Grafana dashboards for Prometheus/Cadvisor: https://grafana.com/grafana/dashboards/?dataSource=prometheus&search=cadvisor
... And, you were asking about CLI ...
I'm not sure I have an answer here.
While scripting directly on top of cadvisor is obviously possible: it could take you some time to figure out what to query. Keeping in mind you would be exclusively working with instantenous values / as opposed to Prometheus, which has functions working with metrics over an interval of time.
If possible, I would still look into Prometheus. And once you have one: this you can query, getting bandwidth consumption per pod, container, ... Even in CLI / there's an API. Maybe writing a kubectl plugin, extending get pods/adm top pods

> **Comments:**
> **username_0**: I guess I will try to write my own plugin. Thank you for the suggestion.  
> **username_2**: I can only see per interface, not pod  

---

### Answer by username_3 on 2023-02-08. Score: 0

Kubecost is a good tool to get the overall usage metrics and associated costs, please take a look here <https://blog.kubecost.com/blog/network-egress-traffic-costs/>


---

