How to filter by multiple container names?

To filter pods by multiple container names, you can modify the jq command to check for multiple conditions. Here's how you can do it:

  1. Get Pods and Filter by Multiple Container Names:

    kubectl get pods -o json | jq '.items[] | select(.spec.containers[].name | IN("container-name-1", "container-name-2")) | {name: .metadata.name, containers: .spec.containers}'

    Replace "container-name-1" and "container-name-2" with the names of the containers you want to filter by.

Breakdown:

  • kubectl get pods -o json: Retrieves all pods in JSON format.
  • jq: A command-line JSON processor.
  • select(.spec.containers[].name | IN("container-name-1", "container-name-2")): Filters the pods to include those that have any of the specified container names.
  • {name: .metadata.name, containers: .spec.containers}: Outputs the pod name and its container details.

This command will return the pods that contain any of the specified container names along with their details. If you have further questions or need more help, feel free to ask!

0 Comments

no data
Be the first to share your comment!