Exemplo n.º 1
0
 def list_all_namespaces(
         cls, crd_api: CustomObjectsApi) -> List["ClusterDeployment"]:
     resources = crd_api.list_cluster_custom_object(
         group=consts.HIVE_API_GROUP,
         version=consts.HIVE_API_VERSION,
         plural=cls._plural,
     )
     return resources
Exemplo n.º 2
0
    def get_node_stats(self, node_name):

        cust = CustomObjectsApi()

        if node_name:
            return cust.get_cluster_custom_object('metrics.k8s.io', 'v1beta1',
                                                  'nodes', node_name)
        else:
            return cust.list_cluster_custom_object('metrics.k8s.io', 'v1beta1',
                                                   'nodes')
Exemplo n.º 3
0
 def top_pods(self):
     custom = CustomObjectsApi(self.api_client)
     data = custom.list_cluster_custom_object("metrics.k8s.io", "v1beta1",
                                              "pods")
     usage_by_pod = collections.defaultdict(list)
     for pod_data in data['items']:
         pod_name = pod_data['metadata']['name']
         for container_data in pod_data['containers']:
             usage_by_pod[pod_name].append({
                 'pod':
                 container_data['name'],
                 'cpu':
                 parse_resource(container_data['usage']['cpu']),
                 'memory':
                 parse_resource(container_data['usage']['memory']) /
                 ONE_MEBI,
             })
     return usage_by_pod
from kubernetes.config import load_kube_config
from kubernetes.client import CustomObjectsApi

# only for running from localhost
load_kube_config()
# if running in the cluster should use load_incluster_config()

cust = CustomObjectsApi()
nodes = cust.list_cluster_custom_object('metrics.k8s.io', 'v1beta1', 'nodes')
pods = cust.list_cluster_custom_object('metrics.k8s.io', 'v1beta1', 'pods')

print(nodes)
print(pods)