Kubernetes - Storing jks file in secrets or configMap

4/9/2018

I have a keystore.jks file which I need to pass as a env variable for my docker process.

I used the below command to store the file as a secret.

kubectl create secret generic ssl-keystore-cert --from-file=./keystore.jks

Using the above secret in my deployment.yaml as below.

{
            "name": "SERVER_SSL_KEYSTORE",
            "valueFrom": {
              "secretKeyRef": {
                "name": "ssl-keystore-cert",
                "key": "keystore.jks"
              }
            }
          }

Error: failed to start container "app-service": Error response from daemon: oci runtime error: container_linux.go:265: starting container process caused "process_linux.go:368: container init caused \"setenv: invalid argument\"" Back-off restarting failed container

Is there anyway to store the keystore.jks in secret or configmap?

Debug :-

kubectl describe secret ssl-keystore-cert

Name:         ssl-keystore-cert
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
keystore.jks:  4818 bytes
-- user1578872
kubernetes

2 Answers

4/9/2018

In your create secret, you refer to keystore.jks

But in your yaml, you refer to server-ssl.jks

These should be the same key, but they are differet.

To verify the correct key, run:

kubectl describe secrets/ssl-keystore-cert

-- Doug
Source: StackOverflow

4/9/2018

I would suggest that you create a Secret for passing Keystore as an environment variable(since it is a confidential information). Having said that the process that you are following is correct. Please check the "key" value that you have passed in the deployment yml file. I see you need the actual content of the file and not the filename. when you do a "kubectl describe secret $secretname" the output contains a Data section. Please update the key value to the value that appears in the Section. If that didn't resolve please send the output of the describe command so that I could take a look at it.

-- Karthick
Source: StackOverflow