We all know that the content of SSL CRT and KEY is a long string of characters broken by new line characters. If we want to use those SSL .crt and .key files with Kubernetes as a TLS secret, they required to be encoded as base64 and be in one-line.
How to do this? Well, there are at least two ways. The first one is my favorite:
$ base64 -w0 drone.example.com.crt
LS0tLS1CRUdJTiBDRVJUSUXXX0FURS0tLS0tCk11SOQrekNDQXVPZ0F3SUJBZ0lVZW5BejFjb0ptakd4Q1dGVHRhOWVzeUM2WHZRd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2dZUXhDekFKQmdOVkJBWVRBa0ZWTVJnd0ZnWURWUVFJREE5T1pYY2dVMjkxZEdnZ1YyRnNaWE14RHpBTgpCZ05WQkFjTUJsTjVaRzVsZVRFUk1BOEdBMVVFQ2d3SVUyRnV0eUJKYm1NeEV6QVJCZ05WQkFNTUNsTmhibmtnClUyVjJaVzR4SWpBZ0Jna3Foa2lHOXcwQkNRRVdFMjV2Y21Wd2JIbEFjMkZ1TjJsdVl5NWpiMjB3SGhjTk1qTXcKTmpFNE1ETTFOVFV4V2hjTk1qVXdPVEl3TURNMU5UVXhXakNCalRFTE1Ba0dBMVVFQmhNQ1FWVXhHREFXQmdOVgpCQWdNRDA1bGR5QlRiM1Yw
...
w0
: disable line wrapping
Another way is to use the good old tr
command:
$ cat drone.example.com.crt | base64 | tr -d '\n'
LS0tLS1CRUdJTiBDRVJUSUXXX0FURS0tLS0tCk11SOQrekNDQXVPZ0F3SUJBZ0lVZW5BejFjb0ptakd4Q1dGVHRhOWVzeUM2WHZRd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2dZUXhDekFKQmdOVkJBWVRBa0ZWTVJnd0ZnWURWUVFJREE5T1pYY2dVMjkxZEdnZ1YyRnNaWE14RHpBTgpCZ05WQkFjTUJsTjVaRzVsZVRFUk1BOEdBMVVFQ2d3SVUyRnV0eUJKYm1NeEV6QVJCZ05WQkFNTUNsTmhibmtnClUyVjJaVzR4SWpBZ0Jna3Foa2lHOXcwQkNRRVdFMjV2Y21Wd2JIbEFjMkZ1TjJsdVl5NWpiMjB3SGhjTk1qTXcKTmpFNE1ETTFOVFV4V2hjTk1qVXdPVEl3TURNMU5UVXhXakNCalRFTE1Ba0dBMVVFQmhNQ1FWVXhHREFXQmdOVgpCQWdNRDA1bGR5QlRiM1Yw
...
tr -d
: translate or delete character.
You can find more about this from the reference [1] below:
Reference: