Skip to content

Instantly share code, notes, and snippets.

@fpytloun
Created January 18, 2019 11:33
Show Gist options
  • Save fpytloun/98f775f2997f8114cc132c280b225e66 to your computer and use it in GitHub Desktop.
Save fpytloun/98f775f2997f8114cc132c280b225e66 to your computer and use it in GitHub Desktop.
Dump kubernetes certificates
#!/bin/bash -e
log_info() {
echo "INFO: $*"
}
log_info "Getting all certificates"
kubectl get certificate --all-namespaces --no-headers | while read cert; do
namespace=$(echo $cert | awk '{print $1}')
name=$(echo $cert | awk '{print $2}')
secret=$(kubectl -n ${namespace} describe certificate ${name} | grep "Secret Name" | cut -d : -f 2 | tr -d ' ')
log_info "Dumping certificate ${name} with secret ${secret} in namespace ${namespace}"
kubectl -n ${namespace} get secret ${secret} -o yaml > secret_${namespace}_${secret}.yml
kubectl -n ${namespace} get certificate ${name} -o yaml > certificate_${namespace}_${name}.yml
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment