kubernetes: Cannot use dash in environment variable names in a pod definition
It’s not possible to define a container with an environment variable containing dash. For example:
...
containers:
- name: my-name
image: gcr.io/id/name:v1
ports:
- containerPort: 8080
env:
- name: SOMETHING_WITH-DASH
value: Something
...
yields the following error:
The ReplicationController "rc-name" is invalid:spec.template.spec.containers[0].env[0].name: invalid value 'SOMETHING_WITH-DASH': must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"
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:
@Value("${something.with-dash}")
private String mySomething;
Spring Boot allows you to externalize the configuration in various different ways. For example it maps environment variables like this:
If you use environment variables rather than system properties, most operating systems disallow period-separated key names, but you can use underscores instead (e.g. SPRING_CONFIG_NAME instead of spring.config.name).
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 to something.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.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 24 (6 by maintainers)
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
bootstrap.memory_lock=true. This causes the following error:The docker-compose.yml file for the lazy:
I was able to sidestep this issue in .Net Core by replacing colons with double underscores.
I’d rather see this get fixed, as weird as it is.
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: