Dynamically set values in Kubernetes yaml configuration files

10/21/2019

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
kubernetes

2 Answers

10/22/2019

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
Source: StackOverflow

10/21/2019

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
Source: StackOverflow