3

Is it possible to dynamically set values in a Kubernetes ingress definition yaml file?

For example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: api-ingress
  annotations:
    kubernetes.io/ingress.class: "traefik"
    kubernetes.io/tls-acme: "true"
spec:
  tls:
  - hosts:
    - api.mydomain.com
  rules:
  - host: api.mydomain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: api
          servicePort: http

I want to extract out the hardcoded domain api.mydomain.com and either use a value from an environment variable, or even better some sort of abstraction config value.

Justin
  • 42,716
  • 77
  • 201
  • 296
  • 2
    Possible duplicate of [How to set dynamic values with Kubernetes yaml file?](https://stackoverflow.com/questions/48296082/how-to-set-dynamic-values-with-kubernetes-yaml-file) – David Maze Oct 21 '19 at 23:25

2 Answers2

0

You can do this with any templating package really, like jinja2 or Go templates. That would be done before submitting the resource to the api-server, but there's no native way to do it dynamically in Kubernetes. Ingresses don't have environment variables or a way to reference configmaps.

You might also want to check out https://kustomize.io/ or https://helm.sh/

switchboard.op
  • 1,878
  • 7
  • 26
0

As already mentioned, that's precisely what kustomize was made for.

Other templating solutions include Kapitan, ksonnet, kubecfg, ytt, yq, and Helm (more than just templating, it's also a "package manager").

weibeld
  • 13,643
  • 2
  • 36
  • 50