0

I have a 3rd party docker container which takes arguments of the form:

docker run foo --arg1 val1 --arg2 val2

and I have run it as a pod in kubernetes as follows:

spec:
  containers:
  - name: foo
    image: foo
    args:
    -  --arg1
    - val1
    - --arg2
    - val2

This is good but I now need to have the two argument values dynamic. For example, val1 is the pod's name/id, and val2 is the zone (aws availability zone) of the node that the Pod is running on.

The only solution so I could think of is, to extend the container creating another image that runs a wrapper script, which queries for these two values and then pass them to the command line.

I am wondering if there's a more elegant solution than that. Let's say we can obtain these dynamic values in an initContainer. Now the question is how do we pass them on the command line of the main container.

PS: It looks like we can get the pod's name using Downward API. However, the Downward API does not expose node's label, for which there is an open issue. So, for this question, let's think our parameters are arbitrary and are obtained dynamically.

1 Answer 1

2

You will be able to pass arguments as mentioned below.

HOSTNAME env will provide the detail for POD_NAME

AWS Region specific details.

OR

Run kubectl command on intialization and use node label with --show-labels to get region specific details based on assigned pod node.

Sign up to request clarification or add additional context in comments.

1 Comment

Alright, this is what I am close to getting to work too right now - call the k8s api from an init container and put the result in a shared volume. This is still good amount of complexity but this is the best so far on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.