Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access env vars in pod cmd #1309

Closed
Gurpartap opened this issue Sep 13, 2014 · 3 comments
Closed

Cannot access env vars in pod cmd #1309

Gurpartap opened this issue Sep 13, 2014 · 3 comments

Comments

@Gurpartap
Copy link
Contributor

I found this while working on using the same standard redis image for both the master and the salve. While the master pod is content with the image's defaults, the slave needs the master's address and port.

One way of doing this is by overriding the image's CMD to add --slaveof $ADDR $PORT in the pod template. Assuming $ADDR and $PORT are the env variables defined by kubernetes.

This, however, will only work if the command is passed to docker as a string to run it under sh -c (which is the only easy way — right? — for the executable to have the substituted values for the env vars supplied). Using the array based command executes it without shell, where these env vars are not substituted and the slave is passed "$ADDR" and "$PORT" directly as strings.

From the docker docs:

The CMD instruction has three forms:

CMD ["executable","param1","param2"] (like an exec, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (as a shell)

Pull request #1299 depends on this.

@thockin
Copy link
Member

thockin commented Sep 14, 2014

This is a good issue. I don't see an easier way to make the join you;re describing without bouncing through the shell or doing text subst ourselves (which we really don't want to do). Can anyone see any better way to do this?

@Gurpartap
Copy link
Contributor Author

I figured out a legitimate workaround.

{ "command": [ "sh", "-c", "redis-server /etc/redis/redis.conf --slaveof $SERVICE_HOST $REDIS_MASTER_SERVICE_PORT"] }

@bketelsen
Copy link
Contributor

This would be good in a FAQ somewhere.

@jbeda jbeda mentioned this issue Sep 17, 2014
@jbeda jbeda closed this as completed Sep 17, 2014
Gurpartap added a commit to Gurpartap/kubernetes that referenced this issue Sep 18, 2014
Port of current guestbook's README.md

Fix guestbook pod and service names

Add go boilerplate

Use role label for redis pods

Give service.containerPort a name based value

This gives better env variable keys like REDIS_MASTER_SERVICE_REDIS_SERVER_ADDR, etc.

Avoid unnecessarily long names for service (esp in env vars)

Adding guestbook deploy/destroy scripts for k8s

These are probably only useful for quick testing. Maybe remove them
before merging the pull request.

Part of avoiding long names for services

Update Dockerfiles to git clone from Google's repo

Use correct service names while deleting them

Fix the script usage path.

K8s is not go gettable. Use git clone instead.

Using my fork in the Dockerfile to release and update to the docker hub
image.

Doesn't delete all pods if you remove controller too soon

Run the command in a shell to substitute env vars. Workaround for kubernetes#1309

GoogleCloudPlatform in lieu of my fork in Dckrfile

Some directory structure changes for guestbook src

README that explains the build process for source

Strip down the html and css to absolute essentials

Reformat JS according to Google's guidelines

Also added code to set random colors for elements.

Handle repetitive error checks using a common func

Also uses @roberthbailey’s stripped down code for reading env vars

infoString isn't really a string. Use info instead

Remove deploy.sh/destroy.sh scripts

Bind submit instead of keypress to capture submit

Add links to /env and /info in the footer

Reformat the JS

Incorporating suggestions by @filbranden

License boilerplate and some fixes to release.sh

Update README.md

Update README.md

Add building on boot2docker info to README

Accept docker bin path as a param for building

Use kubernetes user to host the image on registry

Don't get included in k8s's recursive build deps

kubernetes#1299 (comment)
17638061
pdecat added a commit to pdecat/cloudsql-proxy that referenced this issue Feb 28, 2017
…les cannot be evaluated directly in command

The region part of the fully qualified instance parameter was missing: `project:region:name`.

Also, I removed the $ sign to avoid letting us think we can evaluate environment variable specified in command directly.
A workaround would be to wrap the command into `sh -c` but this docker image does not include any shell (`FROM scratch`).
cf. kubernetes/kubernetes#1309 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants