Openshift: Get current pod name

7/4/2018

I'd like to know wether I'm able to restart a pod or do a deploy using api.

I'm running a container in a pod it's watching out on a directory. When a change is made on a directory, I need to restart the pod, or do a deploy.

This is my shell script snippet:

while inotifywait -e modify $ENV_LOCATION; do
    curl -k \
      -X DELETE \
      -H "Authorization: Bearer $TOKEN" \
      -H 'Accept: application/json' \
      -H 'Content-Type: application/json' \
      $SERVER_URL/api/v1/namespaces/$NAMESPACE/pods/$NAME
done

So, how could I get current pod name?

Any ideas?

-- Jordi
kubernetes
openshift

1 Answer

7/4/2018

Take a look at here.

You can use metadata:

  - name: <name>
    image: <image>
    env:
    - name: KUBERNETES_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
    - name: POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
-- Jordi
Source: StackOverflow