# at namespace level
oc api-resources --namespaced=true
# at cluster level
oc api-resources --namespaced=false
oc explain bc
oc explain bc.spec
oc explain bc.spec.completionDeadlineSeconds
oc explain dc
oc explain dc.spec
oc explain dc.spec.template
oc explain dc.spec.template.spec
oc explain dc.spec.template.spec.volumes
oc get pod/<pod> -o custom-columns=namespace:metadata.namespace,name:metadata.name,nodeName:spec.nodeName
oc get route --all-namespaces -o json | jq '.items[] | select ( .status.ingress[].conditions[] | .type == "Admitted" and .status == "False")'
## Prettier output (columns)
oc get route --all-namespaces -o json | jq -r '["namespace", "name", "reason"], (.items[] | select ( .status.ingress[].conditions[] | .type == "Admitted" and .status == "False") | [.metadata.namespace, (.kind +"/"+.metadata.name), ( .status.ingress[].conditions[].reason)]) | @csv' | column -ts,
# as of 3.9
oc get '--raw=/apis?limit=500' | jq -crM '.groups[] | .preferredVersion.groupVersion' | ( xargs -I {} oc get '--raw=/apis/{}?limit=500' | jq -crM '.resources[] | select(.categories | values | .[] | . == "all" ) | .name' )
Reference: openshift/origin#18396 (comment)
oc get '--raw=/apis?limit=500' | jq -crM '.groups[] | .preferredVersion.groupVersion' | ( xargs -I {} oc get '--raw=/apis/{}?limit=500' | jq -crM '.resources[] | .name' )
oc get project -o custom-columns=name:.metadata.name,project-set:.metadata.labels.name,product:.metadata.labels.product,product-owner:.metadata.annotations.product-owner,product-lead:.metadata.annotations.product-lead
oc get project -o custom-columns=NAME:.metadata.name,PROJECT-SET:.metadata.labels.name,DISPLAY-NAME:.metadata.annotations.openshift.io/display-name
oc get project -o 'custom-columns=NAME:.metadata.name,PROJECT-SET:.metadata.labels.name,TEAM:.metadata.labels.team,DISPLAY-NAME:.metadata.annotations.openshift\.io/display-name'
oc get project -o 'custom-columns=NAME:.metadata.name,PROJECT-SET:.metadata.labels.name,TEAM:.metadata.labels.team,MCIO:.metadata.labels.mcio,DISPLAY-NAME:.metadata.annotations.openshift\.io/display-name'
# to a CSV file:
oc get namespace -l environment=prod -o json | jq -r '.items[] | . as $p | ["namespace", "product", "MCIO", "ProductOwner", "ProductLead", "DisplayName", "Description"], [$p.metadata.name, $p.metadata.labels.product // "<null>", $p.metadata.labels.mcio, $p.metadata.annotations["product-owner"], $p.metadata.annotations["product-lead"], $p.metadata.annotations["openshift.io/display-name"], $p.metadata.annotations["openshift.io/description"]] | @csv' > all-prod-products.csv
oc get namespace -l environment=prod -o json | jq -r '[.items[] | . as $p | [$p.metadata.name, $p.metadata.labels.product // "<null>", $p.metadata.labels.mcio, $p.metadata.annotations["product-owner"], $p.metadata.annotations["product-lead"], $p.metadata.annotations["openshift.io/description"]]] | ["namespace", "product", "MCIO", "ProductOwner", "ProductLead", "DisplayName", "Description"], .[] | @csv'
oc get pvc -o custom-columns=namespace:.metadata.namespace --all-namespaces --no-headers | sort | uniq -c | sort -n
# Top 10 namespaces using most PVCs
oc get pvc -o custom-columns=namespace:.metadata.namespace --all-namespaces --no-headers | uniq -c| awk '$1>4' | sort -r | head -n 10
# more than 10 PVC per namespace
oc get pvc -o custom-columns=namespace:.metadata.namespace --all-namespaces --no-headers | uniq -c| awk '$1>=10' | sort -r
#currently selected project/namespace
# Option 1
oc get imagestreams -o json | jq -r '.items[] | {imageStream:.metadata.name, image:.status.tags[]?.items[].image} | (.imageStream + "@" + .image)' | xargs -I {} oc get 'imagestreamimage/{}' -o json | jq -r '.image.dockerImageLayers[] | (.name + "\t" + (.size | tostring))' | sort | uniq | awk '{ sum += $2 } END { print sum }' | awk '{ foo = $1 / 1024 / 1024 / 1024 ; print foo "GB" }'
# Option 2
oc get imagestreams -o json | jq -r '.items[] | {imageStream:.metadata.name, image:.status.tags[]?.items[].image} | (.imageStream + "@" + .image)' | xargs -I {} oc get 'imagestreamimage/{}' -o json | jq -r '.image.dockerImageLayers[] | {name: .name, size: .size}' | jq -sr 'unique_by(.name) | .[].size' | awk '{ sum += $1 } END { print (sum / 1024 / 1024 / 1024) "GB" }'
oc delete pods --field-selector 'status.phase!=Running'