Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an SpringBoot array property as a kubernetes secret?

I want to use the direct translation from k8s secret-keys to SpringBoot properties. Therefore I have a helm chart (but similar with plain k8s):

apiVersion: v1
data:
  app.entry[0].name: {{.Values.firstEntry.name | b64enc }}
kind: Secret
metadata:
  name: my-secret
type: Opaque

With that my intention is that this behaves as if I'd set the spring property file:

app.entry[0].name: "someName"

But when I do this I get an error:

 Invalid value: "[app.entry[0].name]": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name',  or 'KEY_NAME',  or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+'),

So, [0] seems not to be allowed as a key name for the secrets.

Any idea how I can inject an array entry into spring directly from a k8s secret name?

Shooting around wildly I tried these that all failed:

  • app.entry[0].name: ... -- k8s rejects '['
  • app.entry__0.name: ... -- k8s ok, but Spring does not recognize this as array (I think)
  • "app.entry[0].name": ... -- k8s rejects '['
  • 'app.entry[0].name': ... -- k8s rejects '['
like image 921
towi Avatar asked Nov 01 '25 07:11

towi


1 Answers

You should be able to use environnment variables like described in sprint-boot-env.

app.entry[0].name property will be set using APP_ENTRY_0_NAME environment variable. This could be set in your deployment.

Using secret like:

apiVersion: v1
data:
  value: {{.Values.firstEntry.name | b64enc }}
kind: Secret
metadata:
  name: my-secret
type: Opaque

and then use it with

       env:
       - name: APP_ENTRY_0_NAME
         valueFrom:
           secretKeyRef:
             name: my-secret
             key: value
like image 119
mpromonet Avatar answered Nov 03 '25 03:11

mpromonet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!