0

I would like to have some Kubernetes ingress configuration like this:

  • DEV environment
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: shop-page-ingress
  annotations:
    nginx.org/server-snippets: |
      location / {
        proxy_pass          https://luz-shop:8443/shop.php?env=SHOP-DEV
        proxy_redirect      https://luz-shop:8443/ https://$host;
      }
  • TEST environment
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: shop-page-ingress
  annotations:
    nginx.org/server-snippets: |
      location / {
        proxy_pass          https://luz-shop:8443/shop.php?env=SHOP-TEST
        proxy_redirect      https://luz-shop:8443/ https://$host;
      }

The only one different thing is the query parameter between 2 environments: env=SHOP-DEV. The question is that I would organize these overlays by kustomize but I don't know it is possible or not? Can I have the BASE configuration with variable ${ENV_NAME} like below and specify the value in the overlay configurations yaml?

  • BASE yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: shop-page-ingress
  annotations:
    nginx.org/server-snippets: |
      location / {
        proxy_pass          https://luz-shop:8443/shop.php?env=${ENV_NAME}
        proxy_redirect      https://luz-shop:8443/ https://$host;
      }
bkl
  • 35
  • 1
  • 7

1 Answers1

1

Not directly. Kustomize doesn't handle unstructured replacement. However it is extensible via a plugins system and those can be arbitrary code either in bash or Go (or the newer KRM stuff from kpt). One of the example plugins uses sed to run arbitrary replacements https://github.com/kubernetes-sigs/kustomize/blob/master/plugin/someteam.example.com/v1/sedtransformer/SedTransformer

Another option is to use a pipeline like kustomize build | envsubst.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thank you. With your comment "Kustomize doesn't handle unstructured replacement.", I think my expectation cannot be reached by original kustomize. – bkl May 08 '21 at 09:11