Rest endpoint to get pod whose name starts with a certain string

1/9/2020

openshift document says we can use the below to get pod by name:

curl -k \
    -H "Authorization: Bearer $TOKEN" \
    -H 'Accept: application/json' \
    https://$ENDPOINT/api/v1/namespaces/$NAMESPACE/pods/$NAME

I want to get a pod that starts with a certain string with a * wild card in the end.

Example:

curl -k \
    -H "Authorization: Bearer $TOKEN" \
    -H 'Accept: application/json' \
    https://$ENDPOINT/api/v1/namespaces/$NAMESPACE/pods/mypod*

but this does not work.

how do i achieve what i needed?

-- lr-pal
kubernetes-helm
openshift
redhat

1 Answer

1/27/2020
  1. Your should use list api get all Pods in a namespace
  2. Selection by fields and labels are limited. Only equality or set-based operations for label selectors; and =, ==, != operators for field selectors.
  3. Of cause it depends on use cases of rest api but in bash environment you have jq to match objects:

    curl -k -H "Authorization: Bearer $TOKEN" -H 'Accept: application/json' https://master.lab1.example.com:8443/api/v1/namespaces/test/pods | jq '.items[] | select(.metadata.name | match("^test"))'
-- Oligzeev
Source: StackOverflow