<p>I want to pass a certificate which is stored in the cluster as a secret. I have this piece of code failing:</p>
<pre><code>method(param1, param2, os.environ['CERTIFICATE']){
     # param1: Does something
     # param2: Does something
     # param3: local path to pem cert used for auth

}
</code></pre>
<p>Error is that &quot;File name too long: '---BEGIN PRIVATE KEY---...........'&quot;. I think - param3 requires a file path, but because I pass the certificate content directly as an environment variable, and not a file path which references the cert - it fails.</p>
<p>Not sure if mounting the secret as volume would make any difference. The cert is stored as follows, I only need tls.key:</p>
<pre><code>    Type:  kubernetes.io/tls

Data
====
tls.crt:  1880 bytes
tls.key:  5204 bytes
</code></pre>

HC LW
<p>Why are you exposing the private key in an environment variable if your application expects a file? Just <a href="https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume" rel="nofollow noreferrer">mount the secret as a file</a> instead. If you have a Secret named &quot;my-secret&quot; with keys <code>tls.crt</code> and <code>tls.key</code>, then you can do something like this:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  volumes:
  - name: my-secret
    secret:
      secretName: my-secret
  containers:
  - name: example
    image: my-image
    volumeMounts:
    - name: my-secret
      mountPath: &quot;/certificate&quot;
</code></pre>
<p>This would result in the container having the certificate and key mounted at <code>/certificate/tls.crt</code> and <code>/certificate/tls.key</code>.</p>
