-
Which kubernetes context:
kubectl config current-context kubectl get nodes -o wide
kubectl describe node | more
> kubectl get pods [pod-name-here] -n [namespace] -o jsonpath='{.spec.containers[*].name}'
kubectl get no -o go-template='{{range .items}}{{if .spec.unschedulable}}{{.metadata.name}} {{.spec.externalID}}{{"\n"}}{{end}}{{end}}'
or
kubectl get no -o go-template="{{range .items}}{{if .spec.unschedulable}}{{.metadata.name}} {{.spec.externalID}}:{{end}}{{end}}" | tr ":" "\n"
author - could not find an easy way to print newline characters with inline golang template, so used a trick printing colons and using tr to convert colons to newlines.
Kubectl supports a superset of JSONPath, with a special range keyword to iterate over ranges, using the same trick to add newlines:
kubectl get no -o jsonpath="{range.items[?(@.spec.unschedulable)]}{.metadata.name}:{end}" | tr ":" "\n"
Print custom columns [Node]
kubectl get no -A -o=custom-columns=NAME:.metadata.name,CPU:.status.allocatable.cpu
Service :
kubectl get svc -A -o=custom-columns=Pod-Name:.metadata.name,Cluster-IP:spec.clusterIP
Search Criteria :
items[].metadata.name=="kube-dns"
Field to retrieve value for matching search :
items[].spec.clusterIP
kubectl get svc -n kube-system -o=jsonpath='{.items[?(@.metadata.name=="kube-dns")].spec.clusterIP}'
kubectl get pods --sort-by={metadata.creationTimestamp}