Answer a question

Is it possible to have array as environmental variable in deployment?

kind: Deployment
metadata:
  name: array-deployment
  namespace: array-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: array-deployment
  template:
    metadata:
      labels:
        app: array-deployment
    spec:
      containers:
      - name: array-deployment
        image: array-deployment:beta
        env:
        - name: ENV_PROJECTS
          value: "project1"
        ports:
        - containerPort: 80
        resources: {}

For an example, I want to have an array of projects for ENV_PROJECT.

Answers

Environment variables are plain strings and do not support arrays as input

In order to achieve what you want, you would want to pass the values as a comma separated list. (You might want to use some other separator if your data contains ,)

so your yaml manifest would become

    - name: ENV_PROJECTS
      value: "project1,project2"

This assumes that your code in the image array-deployment:beta supports reading comma separated values from the env var

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐