Requirement
I’ve asked to list the limits and requests for all pods in a specific namespace in k8s.
Implementation
To achieve this, you can use the kubectl command to show a single pod's limits and requests. all
kubectl
commands are listed on the Kubernetes website.
kubectl get pods <podname> -o jsonpath='{range .spec.containers[*]}{"Container Name: "}{.name}{"\n"}{"Requests:"}{.resources.requests}{"\n"}{"Limits:"}{.resources.limits}{"\n"}{end}'
For printing out the limits and requests for all pods, we need to get all pod names and pass pod names to replace nacos-0, so the command would be
for pod in $(kubectl get pod --output=jsonpath={.items..metadata.name}); do kubectl get pods $pod -o jsonpath='{range .spec.containers[*]}{"Container Name: "}{.name}{"\n"}{"Requests:"}{.resources.requests}{"\n"}{"Limits:"}{.resources.limits}{"\n"}{end}'; done