kustomize: are simple variable substitutions supported?

487 views
Skip to first unread message

oliver...@braintribe.com

unread,
Jul 6, 2018, 4:47:51 AM7/6/18
to kubernetes-sig-cli
I recently discovered the kustomize project, and hope that it could replace our make/sed combination. So far I had success with it for the most part.

One thing that I'm missing (or did not find documentation on) is how to do simple variable substitution. For example, given the following ingress definition:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: tf-flow
spec:
  rules:
    - host: tf-flow.@@DOMAIN@@
      http:
        paths:
          - backend:
              serviceName: scdf-server
              servicePort: 80
            path: /


At the moment I use sed to replace the @@DOMAIN@@ placeholder with a concrete value, and I would like to utilize kustomize for that. Is that something that can be done with kustomize?

thanks!

Antoine Pelisse

unread,
Jul 9, 2018, 5:20:40 PM7/9/18
to oliver...@braintribe.com, kubernetes-sig-cli
Hey Oliver,

Can you tell us more about what you're trying to do? How many instances of this ingress do yo have? What is the reason for using sed rather than hard-coding the specific values?

Thanks,
Antoine

--
You received this message because you are subscribed to the Google Groups "kubernetes-sig-cli" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-...@googlegroups.com.
To post to this group, send email to kubernete...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-sig-cli/32920477-6d1a-4199-a10b-78f713c8e874%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

oliver...@braintribe.com

unread,
Jul 10, 2018, 3:54:34 AM7/10/18
to kubernetes-sig-cli
Hi Antoine


On Monday, July 9, 2018 at 11:20:40 PM UTC+2, Antoine Pelisse wrote:
Hey Oliver,

Can you tell us more about what you're trying to do? How many instances of this ingress do yo have? What is the reason for using sed rather than hard-coding the specific values?
In general, I wanted to replace my make/sed based approach to generalizing Kubernetes manifests with kustomize. I'm especially happy about the overlay concept, which fits my needs pretty well.

In this particular case, I have a set of manifests that describe a Spring Cloud Data Flow deployment. Those deployments will be per client, and each client can have dev/stage/production stages. The entrypoints are specific URLs which are handled and routed by the ingress, and for each client/stage combination there is a particular URL similar to this:

client1:
  dev
: dev.tf-flow.client1.mydomain.com
  test
: test.tf-flow.client1.mydomain.com

client2
:
  dev
: dev.tf-flow.client2.mydomain.com
  test
: test.tf-flow.client2.mydomain.com

And the placeholder version of this would look like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: tf-flow
spec:
  rules:
   - host: @@STAGE@@.tf-flow.@@DOMAIN@@
     http:
       paths:
         - backend:
             serviceName: scdf-server
             servicePort: 80
           path: /


I usally have a sed that looks like this

sed 's|@@STAGE@@|$(STAGE)|g' ingress.yaml | sed 's|@@DOMAIN@@|$(DOMAIN)|g' | kubectl apply -f -

In this particular case, of course, it could also just be the full URL:


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tf-flow
spec:
  rules:
  - host: @@HOST@@
    http:
      paths:
        - backend:
            serviceName: scdf-server
            servicePort: 80
          path: /


So, in the snippet above, would that be doable with kustomize?

Thanks!

Oliver 

Antoine Pelisse

unread,
Jul 11, 2018, 6:25:47 PM7/11/18
to oliver...@braintribe.com, kubernetes-sig-cli
I don't think kustomize supports templates nor will it ever support
them. How many "clients" do you have? Would it be reasonable to have one
directory for each client/stage? I think the kustomize pattern would be to
"sed and replace/commit/apply" rather than "commit/sed and
replace/apply". It also makes individual client customization
simpler. If it's unreasonable to have one configuration committed
per client (either because the list of clients is coming from a
dynamic-set/database or because you have thousands), then it's 
also reasonable to have ksonnet on top of kustomize.

Hope this helps,
Antoine

--
You received this message because you are subscribed to the Google Groups "kubernetes-sig-cli" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-...@googlegroups.com.
To post to this group, send email to kubernete...@googlegroups.com.

Daniel Smith

unread,
Aug 2, 2018, 5:45:28 PM8/2/18
to Antoine Pelisse, oliver...@braintribe.com, kubernetes-sig-cli
FWIW I found a similar use case, which is using the same image in multiple containers in a pod. It's a pain to change the image N times in an overlay just to update the version.

jingf...@google.com

unread,
Aug 3, 2018, 2:42:47 PM8/3/18
to kubernetes-sig-cli
Daniel, recently kustomize added a new feature to support changing image tags by adding 
imageTags:
  -name: some/repo/myimage
   newTag: my.new.tag

To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-cli+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "kubernetes-sig-cli" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-cli+unsub...@googlegroups.com.

Brian Grant

unread,
Aug 3, 2018, 2:45:44 PM8/3/18
to Jingfang Liu, kubernetes-sig-cli

To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "kubernetes-sig-cli" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "kubernetes-sig-cli" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-sig-...@googlegroups.com.

To post to this group, send email to kubernete...@googlegroups.com.

Jingfang Liu

unread,
Aug 3, 2018, 3:10:06 PM8/3/18
to Brian Grant, kubernete...@googlegroups.com
digests are not supported. We haven't seen requests for that from Kustomize users.
If we need this feature, I can see the format of specifying a new digest should be similar to newTag.

Brian Grant

unread,
Aug 3, 2018, 3:24:02 PM8/3/18
to Jingfang Liu, kubernetes-sig-cli
What people have asked for is rolling update at the same tag:

Digest is the right way to support that.

Jingfang Liu

unread,
Aug 3, 2018, 6:13:27 PM8/3/18
to Brian Grant, Jeffrey Regan, kubernete...@googlegroups.com
Just finished reading the long discussion in the issue https://github.com/kubernetes/kubernetes/issues/33664 and got some understanding of the context.
People who want the rolling update at the same tag seems to have different workarounds. Replacing tags by digests are also provided by some platforms, such as Openshift.

if we want Kustomize to support that, it can be done through an extra transformation with steps as talking to image registry, getting the digest and replacing the tag. However, I am hesitated to go that way. Since it will add external dependency to Kustomize. It will also make the configuration not fully determined until one runs `kustomize build`.  +Jeffrey Regan  What do you think about this?

For the original Ingress sed problem, there is a feature request which can help. https://github.com/kubernetes-sigs/kustomize/issues/169
Reply all
Reply to author
Forward
0 new messages