I’d like to import the output of:
kubectl get pods -o json
into a python pandas dataframe. This should contain also all containers and there resource request and limits.
My code starts as follows:
import json
import numpy as np
import pandas as pd
import os
pods_raw = os.popen('kubectl get pods -o json').read()
pods_json = json.loads(pods_raw)['items']
from here on I struggle to get the data in a correct way in a dataframe, especially the ‘spec.containers’ should be split up when multiple containers exist.
2
Answers
Currently I have the following code to solve this:
This works fine except for the following FutureWarning I get and don't know how to solve this yet:
df = pd.concat( [df, df.pop(expantion).apply(pd.Series).add_prefix(f"{expantion}.")], axis=1)
Here is an example how you can extract the data of interest to the dataframe. The output is only an example (as you didn’t specify the required output in the question):
Prints: