Kubernetes Container Environment

12/11/2018

I wrote deployment.yml file in k8s:-

spec:
  containers:
  - name: consul
    image: xyz
    ports:
      - name: http
        containerPort: 8500
      - name: http1
        containerPort: 53
    env:
    - name: SERVICE_8500_IGNORE
      value: "true"
    - name: CONSUL_LOCAL_CONFIG
      value: "{"node_name": "docker","acl_datacenter": "dc1", "acl_default_policy": "deny", "acl_down_policy": "deny", "acl_master_token": "fleeture", "acl_agent_token":"xyz", "enable_script_checks": true}"

After running I am getting errors

Error : Unexpected characters near "node_name": "docker","acl_datacenter": "dc1", "acl_default_policy": "deny", "acl_down_policy": "deny", "acl_master_token": "xyz", "acl_agent_token":"xyz", "enable_script_checks": true}"". Line : 14 value: "{"node_name": "docker","acl_datacenter": "dc1", "acl_default_policy": "deny", "acl_down_policy": "deny", "acl_master_token": "fleeture", "acl_agent_token":"xyz", "enable_script_checks": true}"

Any Idea how to write ENV for line 14?

-- Ankit Singh
kubernetes
kubernetes-helm

2 Answers

12/11/2018

You need to use \ to escape the double-quotes within the value for CONSUL_LOCAL_CONFIG so that entry becomes:

- name: CONSUL_LOCAL_CONFIG
  value: "{\"node_name\": \"docker\",\"acl_datacenter\": \"dc1\", \"acl_default_policy\": \"deny\", \"acl_down_policy\": \"deny\", \"acl_master_token\": \"fleeture\", \"acl_agent_token\":\"xyz\", \"enable_script_checks\": true}"
-- Ryan Dawson
Source: StackOverflow

12/12/2018

@ryan-dawson's answer is valid answer.

Also, you can simply replace first double-quote(") with single-quote(') as

- name: CONSUL_LOCAL_CONFIG
  value: '{"node_name": "docker","acl_datacenter": "dc1", "acl_default_policy": "deny", "acl_down_policy": "deny", "acl_master_token": "fleeture", "acl_agent_token":"xyz", "enable_script_checks": true}' 
-- Abu Hanifa
Source: StackOverflow