-4

I want to set Kubernetes Deployment env with integer value, but I have to quote the value for Kubernetes Deployment to accept it. This makes the env value a string and is causing a TypeError in the app.

Is there any workaround to set integer or float value to env?

3
  • 5
    All environment variables are strings. May 12, 2021 at 16:13
  • Just parseInt() or something similar in your app. May 15, 2021 at 0:32
  • Yes thats what I am doing now, handling type conversion in app.
    – rp346
    May 18, 2021 at 12:27

1 Answer 1

0

Generally it was answered in comment, however I'll add references from official kubernetes documentation.

env field uses EnvVar array. Based on EnvVar v1 core API group, name and value should be only strings. Please see EnvVar v1 core

And here is an official example to see how variables are set:

apiVersion: v1
kind: Pod
metadata:
  name: dependent-envars-demo
spec:
  containers:
    - name: dependent-envars-demo
      args:
        - while true; do echo -en '\n'; printf UNCHANGED_REFERENCE=$UNCHANGED_REFERENCE'\n'; printf SERVICE_ADDRESS=$SERVICE_ADDRESS'\n';printf ESCAPED_REFERENCE=$ESCAPED_REFERENCE'\n'; sleep 30; done;
      command:
        - sh
        - -c
      image: busybox
      env:
        - name: SERVICE_PORT
          value: "80"
        - name: SERVICE_IP
          value: "172.17.0.1"
        - name: UNCHANGED_REFERENCE
          value: "$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)"
        - name: PROTOCOL
          value: "https"
        - name: SERVICE_ADDRESS
          value: "$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)"
        - name: ESCAPED_REFERENCE
          value: "$$(PROTOCOL)://$(SERVICE_IP):$(SERVICE_PORT)"

Link to this example is here

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.