Created
August 7, 2024 06:42
-
-
Save edr3x/cf27238c0cf3b61aecc9e76bba3e20fb to your computer and use it in GitHub Desktop.
create kubernetes tls secrets from json certificate file generated by traefik
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
| #!/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