-1

I have a secret stored in the Kubernetes pod which can be accessible by the following command.

kubectl exec -it pod_name -- printenv | grep SFTP_PASSWORD

which will provide the output as

SFTP_PASSWORD=password

I am accessing this secret in the bash script.

sftp_password=$(kubectl exec -it pod_name -- printenv | grep SFTP_PASSWORD)

But the issue I am facing is the above command will return both key-value pairs instead of value.

2

1 Answer 1

1

If it's an environment variable, you can just use ordinary Bourne shell parameter expansion syntax:

kubectl exec pod_name -- sh -c 'echo $SFTP_PASSWORD'

Note the single quotes, to prevent the local shell from expanding the parameter; the sh -c wrapper so that a remote shell will be started to do the parameter expansion; and in this non-interactive use the -it options are unnecessary.

It's possible your cluster administrator prohibits kubectl exec, to prevent copying secret values out of the cluster in exactly this way. This also avoids the non-standard printenv tool (it is part of GNU Coreutils and not the POSIX spec, so Alpine-based images may not have it).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.