Created
October 13, 2022 09:19
-
-
Save reducedhackers/da20c1f0cd3603a012f8312f6e45a097 to your computer and use it in GitHub Desktop.
Extracting deploy environment values from a running Kubernetes pod using kubectl get deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We had an issue where a development repository of a Nodejs application did not have a dotEnv( .env ) document included. | |
# The environment variables had been defined in a seperate K8s Yaml document which pointed to key:value pairs but this was not | |
# easily pulled into a text file; instead I looked for a way to pull the template container keys out from the running pod as seen | |
# in the example below | |
kubectl get pods --all-namespaces | |
kubectl -n {namespacehere} get deploy {nameofpoddetailedfromprevious} -ojsonpath='{.spec.template.spec.containers[0].env}' | jq -r '.[] | {name,value} | join (" = ")' | |
#note if your environmen varaiables were collecting information specified in a secrets / external configuration you may want to use valuefrom | |
# and then you will need to manually collect each of those secret into that pull as well ( examples given below this one ) | |
kubectl -n namespacehere get deploy nameofpoddetailedfromprevious -ojsonpath='{.spec.template.spec.containers[0].env}' | jq -r '.[] | {name,valuefrom} | join (" = ")' | |
kubectl get secret -n {namespacehere} {nameofpodhere} -o jsonpath="{.data.nameofsecretkeyhere}" | base64 --decode | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment