<p>I am wondering if it is possible to have a byte array as kubernetes secret.
I created a byte array and a base64-encoded string as below</p>

<pre><code>    SecureRandom random = new SecureRandom();
    byte bytes[] = new byte[32];

    random.nextBytes(bytes);
    for (int i = 0; i &lt; bytes.length; i++) {
        System.out.print(bytes[i] + ",");
    }

    String token = Base64.getEncoder().withoutPadding().encodeToString(bytes);
</code></pre>

<p>Then I used the resulting string in a kubernetes secret. The secret gets created successfully.
Now I would like my Spring Boot application, that is running in kubernetes, to read and decode that value.
However, I get an IllegalArgumentException (Illegal base64 character)
When running the application locally reading the same token from a properties file, it can be decoded.</p>

<p>So my question again: Is it possible to use a byte array as kubernetes secret?</p>

Martin Baeumer
<p>The plain value is expected when creating a secret with <code>kubectl create secret generic</code> whether using <code>--from-file</code> or <code>--from-literal</code> (as @fg78nc eluded to).</p>

<p>base64-encoded value is required when <a href="https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-manually" rel="nofollow noreferrer">Creating a Secret Manually</a> from binary value.</p>

<p>If secret's value is a binary value, I'd suggest mounting the secret as a volume and reading it from the file as a byte array - it will be base64-decoded in the file. </p>

<p>The secrets are base64-decoded automatically when getting the value from an environment variable created from the secret, from a file mounted as a volume, but not by <code>kubectl get secret</code> or when directly using the Kubernetes API (<code>GET /api/v1/namespaces/{namespace}/secrets/{name}</code>).</p>
