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 use dash in environment variable names in a pod definition #16863
Comments
Afaik the format requirements of env var names are implementation dependent and the C_IDENTIFIER format is the lowest common denominator. There are a ton of ways to externalize configs for spring - can you use a properties file as a work around instead of environment variables? It does look to me like spring's Also, it does look like environ has some munging that will get around this for you:
Does the environ support unstick you? Seems like it would also probably be possible to write your own property source that does the resolution you want - this will likely be more portable than depending on the shell to support the values you want. |
Thanks for your reply.
While I could do it I don't think it would be optimal for us (please correct me if I'm wrong). We're using continuous delivery and we build one image (containing the spring uberjar for example) but we deploy this image to multiple environments with different configurations. We are currently specifying the configuration in environment variables being read by Spring. We could of course choose to use configuration files instead but afaik we would have to bundle these up with the image (and have one image per environment) or mount a volume and copy the configuration to this location. To me this doesn't sound as simple as the just using environment variables. We're currently using
Sorry I think I was wrong about environ. Thanks for pointing this out. But would you rather say that it's an issue with the way Spring handles environment variables? Perhaps it should try to translate "_" to "-" as well as "."? |
I'm a little surprised that env vars are allowed to be non-C-identifiers, We should fix it, but document it carefully. On Sun, Nov 8, 2015 at 10:55 PM, Johan Haleby notifications@github.com
|
@johanhaleby @thockin I tested with minikube and see the issue with "-" is still there except that with a modified error message "The Pod "containers" is invalid: spec.containers[0].env[0].name: Invalid value: "x-y": must match the regex [A-Za-z_][A-Za-z0-9_]* (e.g. 'my_name' or 'MY_NAME' or 'MyName')" |
I'd rather see this get fixed, as weird as it is. |
:-) sure @thockin !! |
The following use case might be relatively common - The official documentation for setting up Elastic Search via docker provides a docker-compose.yml file with an environment parameter Error from server (Invalid): error when creating "kubernetes/elasticsearch1-deployment.yaml": Deployment.apps "elasticsearch1" is invalid: [spec.template.spec.containers[0].env[0].name: Invalid value: "cluster.name": a valid C identifier must start with alphabetic character or '_', followed by a string of alphanumeric characters or '_' (e.g. 'my_name', or 'MY_NAME', or 'MyName', regex used for validation is '[A-Za-z_][A-Za-z0-9_]*'), spec.template.spec.containers[0].env[1].name: Invalid value: "bootstrap.memory_lock": a valid C identifier must start with alphabetic character or '_', followed by a string of alphanumeric characters or '_' (e.g. 'my_name', or 'MY_NAME', or 'MyName', regex used for validation is '[A-Za-z_][A-Za-z0-9_]*')] The docker-compose.yml file for the lazy: version: '2'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.2
container_name: elasticsearch1
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch1"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata2:/usr/share/elasticsearch/data
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet: |
+1 same issue with elastic here |
I managed to solve this for Spring by replacing dots with underscores. I'm running the PetClinic example in Kubernetes like with these env params:
|
I was able to sidestep this issue in .Net Core by replacing colons with double underscores.
|
Also running into this issue using an environment variable that begins with a number. |
Any updates on this issue? |
Following this one: can't seem to run elastic cluster in openshift due to this restriction.. :( |
+1 |
@mr-falken @parrisvarney did you find a way to run elasticsearch? |
@dguettler, I just gave up and deployed elk cluster on vms.. :) |
What happens if you define the environment variables via a configmap? |
Haven't tried but I would expect the same outcome as the validation fails on the name of the environment variable so I'd expect
to fail with the same validation error as
Looks like Kubernetes 1.8 will allow for above though. So in my case OpenShift 3.9 was just released which is running Kubernetes 1.9 |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
For the sake of others trying to run Elasticsearch on K18S/Openshift and running into this issue, this is how you can handle it:
|
thanks for the answer. Just wondering how do you handle, when the property itself have e.g.
|
It's not possible to define a container with an environment variable containing dash. For example:
yields the following error:
So why is this needed?
I'm trying to deploy an existing Spring Boot Java application running inside a Docker container. Spring boot allows you to inject configuration using this approach:
Spring Boot allows you to externalize the configuration in various different ways. For example it maps environment variables like this:
So in this case I need to use an environment variable called
SOMETHING_WITH-DASH
in order for spring to pick it up and map it tosomething.with-dash
.This works when using tools like Docker Compose. In bash it works when you do like this:
env 'SOMETHING_WITH-DASH=Something' myprogram
It's even more common when using Clojure and the popular environ library that deals with properties. Since Clojure uses Lisp syntax it's very common to name keys using dashes.
Without support for this it'll be harder for me (and presumably others) to sell Kubernetes to my company since we have to make code changes in several projects/services.
I'm using Kubernetes 1.0.6 on Google Container Engine.
The text was updated successfully, but these errors were encountered: