turbot/kubernetes_insights

Query: deployment_tree

Usage

powerpipe query kubernetes_insights.query.deployment_tree

SQL

-- This deployment
select
null as from_id,
uid as id,
name as title,
0 as depth,
'deployment' as category
from
kubernetes_deployment
where
uid = $1
-- replicasets owned by the deployment
union all
select
$1 as from_id,
uid as id,
name as title,
1 as depth,
'replicaset' as category
from
kubernetes_replicaset,
jsonb_array_elements(owner_references) as owner
where
owner ->> 'uid' = $1
-- Pods owned by the replicasets
union all
select
pod_owner ->> 'uid' as from_id,
pod.uid as id,
pod.name as title,
2 as depth,
'pod' as category
from
kubernetes_replicaset as rs,
jsonb_array_elements(rs.owner_references) as rs_owner,
kubernetes_pod as pod,
jsonb_array_elements(pod.owner_references) as pod_owner
where
rs_owner ->> 'uid' = $1
and pod_owner ->> 'uid' = rs.uid
-- containers in Pods owned by the replicasets
union all
select
pod.uid as from_id,
concat(pod.uid, '_', container ->> 'name') as id,
container ->> 'name' as title,
3 as depth,
'container' as category
from
kubernetes_replicaset as rs,
jsonb_array_elements(rs.owner_references) as rs_owner,
kubernetes_pod as pod,
jsonb_array_elements(pod.owner_references) as pod_owner,
jsonb_array_elements(pod.containers) as container
where
rs_owner ->> 'uid' = $1
and pod_owner ->> 'uid' = rs.uid

Params

ArgsNameDefaultDescriptionVariable
$1uid

    Dashboards

    The query is used in the dashboards: