Skip to content

Instantly share code, notes, and snippets.

@edr3x
Created August 7, 2024 06:42
Show Gist options
  • Select an option

  • Save edr3x/cf27238c0cf3b61aecc9e76bba3e20fb to your computer and use it in GitHub Desktop.

Select an option

Save edr3x/cf27238c0cf3b61aecc9e76bba3e20fb to your computer and use it in GitHub Desktop.
create kubernetes tls secrets from json certificate file generated by traefik
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "Usage: $0 <json_file>"
exit 1
fi
json_file="$1"
certificates=$(jq -c '.production.Certificates[]' $json_file)
echo "$certificates" | while IFS= read -r cert; do
key=$(echo $cert | jq -r '.key')
domain=$(echo $cert | jq -r '.domain.main')
certificate=$(echo $cert | jq -r '.certificate')
secret_name=$(echo $domain | tr '.' '-')-tls
echo "$certificate" | base64 --decode > tls.crt
echo "$key" | base64 --decode > tls.key
kubectl create secret tls "$secret_name" --cert=tls.crt --key=tls.key
done
# Cleanup
rm tls.crt tls.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment