Skip to content

OpenShift/Kubernetes Client

clientkubectloc

Templates

List of Pods with resources

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cat > podlist-with-resources.gotemplate <<'EOF'
{{$printf_format := "%-50s\t%-50s\t%-50s\t%s\n" }}
{{- printf $printf_format "NAMESPACE" "POD NAME" "CONTAINER NAME" "RESOURCES" -}}
{{- range .items -}}
    {{- if eq .kind "Pod" -}}
            {{$namespace := .metadata.namespace -}}
            {{$pod_name := .metadata.name}}
        {{- range .spec.containers -}}
            {{$resources := "There are no resources."}}
            {{- if .resources -}}
                {{$resources = .resources }}    
            {{- end -}}
            {{- printf $printf_format $namespace $pod_name .name $resources -}}
        {{- end -}}
    {{- end -}}
{{- end -}}
EOF


oc get pods -n openshift-monitoring -o go-template-file=podlist-with-resources.gotemplate
NAMESPACE                                           POD NAME                                            CONTAINER NAME                                      RESOURCES
openshift-monitoring                                alertmanager-main-0                                 alertmanager                                        map[requests:map[cpu:4m memory:200Mi]]
openshift-monitoring                                alertmanager-main-0                                 config-reloader                                     map[requests:map[cpu:1m memory:10Mi]]
openshift-monitoring                                alertmanager-main-0                                 alertmanager-proxy                                  map[requests:map[cpu:1m memory:20Mi]]
openshift-monitoring                                alertmanager-main-0                                 kube-rbac-proxy                                     map[requests:map[cpu:1m memory:20Mi]]
openshift-monitoring                                alertmanager-main-0                                 prom-label-proxy                                    map[requests:map[cpu:1m memory:20Mi]]
openshift-monitoring                                alertmanager-main-1                                 alertmanager                                        map[requests:map[cpu:4m memory:200Mi]]

... 

Last update: May 5, 2021