kubernetes: dot character in environment variable name yields "invalid value"

I modified the pod json from here https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/getting-started-guides/aws-coreos.md to have this in it:

  "containers": [{
    "name": "hello",
    "env": [
            {
              "name": 'oms.port',
              "value": 9000,
            }],
    "image": "quay.io/kelseyhightower/hello",
    "ports": [{
      "containerPort": 80,
      "hostPort": 80
    }]
  }]

and when I do kubecfg -c pod.json create pods, I get

F1202 08:48:01.907263 04825 kubecfg.go:403] Got request error: pod "hello" is invalid: desiredState.manifest.containers[0].env[0].name: invalid value 'oms.port'

I am using Kubernetes 0.5.4

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 3
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

A workaround for Elasticsearch until this is fixed is to use command arguments in your Kubernetes deployment spec like so:

spec:
  containers:
  - image: docker.elastic.co/elasticsearch/elasticsearch:5.4.2
    ...
    command: ["bin/elasticsearch"]
    args: ["-Ehttp.host=0.0.0.0", "-Etransport.host=127.0.0.1"]

As documented under configuration here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

With the explanation from here quoted on the referenced Docker issue, it seems to me that Kubernetes is similar to Docker in the sense that it’s just an intermediary that should always pass environment variables through to the application even when they contain “illegal characters”; the reason being that applications may not be subject to the same restrictions as bash.

@erictune Do you think this is worth creating a new issue or reopening this one?

@webwurst it’ll only be available in 1.8.

My PR just got merged. Once released, environment variable names with dots (and dashes) should generally be supported.

Sorry to necro this thread. My issue turned out to be because I used “sh” in the command, which strips dotted names. Switching to “bash” allowed the variables to pass through as expected.

Super quick update: I’ve started work on this. Should hopefully be able to submit a PR soonish.

If you are stuck on <1.8 for the time being this fixed it all for me with elasticsearch (the similar answer above didn’t quite cut it) hope this helps someone

      - image: docker.elastic.co/elasticsearch/elasticsearch:6.2.2
...
        command: ["/usr/local/bin/docker-entrypoint.sh"]
        args: ["bin/elasticsearch", "-Ediscovery.type=single-node"]

thanks @mtaufen – will follow up with a PR and see what folks have to say.

@erictune Funnily enough this hit us as well today for elasticsearch. Docker had this restriction and reverted it since POSIX pretty clearly states that you should tolerate env strings you don’t understand. See more in the relevant docker issue https://github.com/docker/docker/issues/16585

The issue (which is still present in Kube 1.5.3) is that a dot is not allowed in the podspec for environment variables names.

Some systems (elasticsearch for example) use dotted env var names. Example:

 - name: transport.host
      value: 127.0.0.1

The above fails with

Deployment.extensions “es-es-kibana” is invalid: spec.template.spec.containers[0].env[2].name: Invalid value: “transport.host”: must match the regex [A-Za-z_][A-Za-z0-9_]*