Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of generating multiple resources from a single template file #4

Open
oxr463 opened this issue May 8, 2022 · 2 comments
Open

Comments

@oxr463
Copy link

oxr463 commented May 8, 2022

In the values.yaml file, we could specify several sites:

sites:
  - name: foo
    source: "foo.com"
  - name: bar
    source: "bar.com
  - name: baz
    source: "baz.com

Then the chart would generate three deployments and three services, one for each site.

Then we could add an ingress that includes each of the services:

spec:
  rules:
  - host: hello-world.com
    http:
      paths:
      - backend:
          service:
            name: foo
            port:
              name: http
        path: /foo
        pathType: Prefix
      - backend:
          service:
            name: bar
            port:
              name: http
        path: /bar
        pathType: Prefix
      - backend:
          service:
            name: baz
            port:
              name: http
        path: /baz
        pathType: Prefix

Then each site would be accessible via the following URLs:

  • hello-world.com/foo
  • hello-world.com/bar
  • hello-world.com/baz
@oxr463 oxr463 changed the title Example of multiple deployment files Example of generating multiple resources from a single template file May 8, 2022
@oxr463
Copy link
Author

oxr463 commented May 10, 2022

I created a new chart:

helm create hello-world-multiple
cd hello-world-multiple
helm template hello-world .

Here is the modified template/deployment.yaml file:

{{- range $key, $value := .Values.repositories }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ $value.name }}
  labels:
    {{- include "hello-world-multiple.labels" $ | nindent 4 }}
spec:
  {{- if not $.Values.autoscaling.enabled }}
  replicas: {{ $.Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "hello-world-multiple.selectorLabels" $ | nindent 6 }}
  template:
    metadata:
      {{- with $.Values.podAnnotations }}
      annotations:
        {{- toYaml $ | nindent 8 }}
      {{- end }}
      labels:
        {{- include "hello-world-multiple.selectorLabels" $ | nindent 8 }}
    spec:
      {{- with $.Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml $ | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "hello-world-multiple.serviceAccountName" $ }}
      securityContext:
        {{- toYaml $.Values.podSecurityContext | nindent 8 }}
      containers:
        - name: hello-world
          securityContext:
            {{- toYaml $.Values.securityContext | nindent 12 }}
          image: "{{ $.Values.image.repository }}:{{ $.Values.image.tag | default $.Chart.AppVersion }}"
          imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- end }}

@oxr463
Copy link
Author

oxr463 commented May 10, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant