0

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.

1 Answer 1

1

Identical resources that have just such small differences are subject to templates.
In Kubernetes, helm 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}}

Your Answer

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

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