Answers: <p>Identical resources that have just such small differences are subject to templates.<br />
  In Kubernetes, <a href="https://helm.sh/" rel="nofollow noreferrer">helm</a> is one tool that can help you solve the issue.<br />
  Create a <code>helm chart</code> that will deploy the needed deployment and template the fields relate to the sports.<br />
  Place a for loop and iterate over the list of sports provided in the values.yaml.<br />
  Example of the idea:</p>
  <pre><code># values.yaml
  sports:
    - baseball
    - football
    - soccer
    - tennis
  
  # templates/pod.yaml
  {{- range .Values.sports }}
  apiVersion: v1
  kind: Pod
  metadata:
    name: {{ . }}-pod
  spec:
    containers:
    - name: {{ . }}-container
      image: my-image
      env:
      - name: SPORT
        value: {{ . }}
  {{- end}}
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-01-20T11:04:03.877Z
Answers: 2023-01-20T11:13:06.633Z
Answers: 2023-01-20T11:13:06.633Z
Answers: igiannak
Body: <p>I have a list of 35 services that need to be continually monitored/exercised. I've got a container that can monitor any one of them and can check an environment variable to see which one of them it should monitor.</p>
  <p>I'd like to tell Kubernetes to please deploy 35 pods of that container, each of them identical except for the environment variable. I could do this by creating 35 nearly identical manifest files and running <code>kubectl create deployment</code> in a loop, but I suspect there's probably a better way. How do I best tell Kubernetes &quot;please take this list of N strings and deploy one pod for each of them, each being assigned one of them?&quot;</p>
  <p>For example, if I've got a list like:</p>
  <pre><code>baseball
  football
  soccer
  tennis
  </code></pre>
  <p>I'd like create a bunch of deployments that are identical, except for their name (preferably I'd include the name from the list as part of the name) and one environment variable telling the container which sport to monitor.</p>
  
Tags: <kubernetes>
Title: Creating a set of of kubenertes pods from a list of arguments
UserDisplayName: Brandon Yarbrough
ThreadText: # Creating a set of of kubenertes pods from a list of arguments
  
  (Asked by: username_0 on 2023-01-19)
  
  I have a list of 35 services that need to be continually monitored/exercised. I've got a container that can monitor any one of them and can check an environment variable to see which one of them it should monitor.
  
  I'd like to tell Kubernetes to please deploy 35 pods of that container, each of them identical except for the environment variable. I could do this by creating 35 nearly identical manifest files and running `kubectl create deployment` in a loop, but I suspect there's probably a better way. How do I best tell Kubernetes "please take this list of N strings and deploy one pod for each of them, each being assigned one of them?"
  
  For example, if I've got a list like:
  
  ```
  baseball
  football
  soccer
  tennis
  
  ```
  
  I'd like create a bunch of deployments that are identical, except for their name (preferably I'd include the name from the list as part of the name) and one environment variable telling the container which sport to monitor.
  
  **Tags:** kubernetes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-01-20. Score: 1
  
  Identical resources that have just such small differences are subject to templates.  
  In Kubernetes, [helm](https://helm.sh/) is one tool that can help you solve the issue.  
  Create a `helm chart` that will deploy the needed deployment and template the fields relate to the sports.  
  Place a for loop and iterate over the list of sports provided in the values.yaml.  
  Example of the idea:
  
  ```
  # values.yaml
  sports:
    - baseball
    - football
    - soccer
    - tennis
  
  # templates/pod.yaml
  {{- range .Values.sports }}
  apiVersion: v1
  kind: Pod
  metadata:
    name: {{ . }}-pod
  spec:
    containers:
    - name: {{ . }}-container
      image: my-image
      env:
      - name: SPORT
        value: {{ . }}
  {{- end}}
  
  ```
  
  
  ---
  
  