0

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.

2 Answers 2

1

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

1
  • I guess I will try to write my own plugin. Thank you for the suggestion.
    – iRakic
    Commented Feb 20, 2023 at 19:26
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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.