Skip to content

how to get pod or node metrics info #1315

Answered by mateiidavid
vCassius asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a different way to do it with a DynamicClient, this would be the equivalent of kubectl top

use kube::{core::DynamicObject, Api, Resource, ResourceExt};
use serde::Deserialize;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = kube::Client::try_default().await?;
    let apigroup = kube::discovery::group(&client, "metrics.k8s.io").await?;
    let res = apigroup.recommended_resources();
    for (ar, _caps) in res {
        println!("Ar: {ar:?}");
    }
    let (ar, _caps) = apigroup.recommended_kind("NodeMetrics").unwrap();
    let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
    for obj in api.list(&Default::default()).await? {
        let (name,

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vCassius
Comment options

@mateiidavid
Comment options

Answer selected by vCassius
@vCassius
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants