0

I use OpenSSL & generated self signed certificate & key files.

Now I try to transform them to base64 encoded value in order to put into kubernetes "Secret" manifest. I tried the answer from this post.

But the accepted answer doesn't work for me, this is what I get:

cat myapp.com.crt | base64 -w0
base64: invalid argument -w0
Usage:  base64 [-hDd] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -Dd, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)

Why is that? How to get the base64 encoded value for my certificate so that I can use the value in k8s secret manifest?

user842225
  • 5,445
  • 15
  • 69
  • 119

3 Answers3

1

What kind of distro are you using? It seems that your base64 binary is not the same program as used in your referenced answer.

On Ubuntu (20.04) it should work:

base64 --help
Usage: base64 [OPTION]... [FILE]
Base64 encode or decode FILE, or standard input, to standard output.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -d, --decode          decode data
  -i, --ignore-garbage  when decoding, ignore non-alphabet characters
  -w, --wrap=COLS       wrap encoded lines after COLS character (default 76).
                          Use 0 to disable line wrapping

      --help     display this help and exit
      --version  output version information and exit

Or you can just use cat server.csr | base64 | tr -d '\n' as mentioned in this answer.

dijkdev
  • 59
  • 6
-1

You can simply specify the files as parameters for the kubectl create secret tls command. You can find more explanations and examples in the docs.

Yaron Idan
  • 6,207
  • 5
  • 44
  • 66
  • This answer is essentially just a link to the documentation. Can you [edit] it to include enough details that it stands alone? – David Maze Feb 21 '23 at 11:42
-1

No need to cat, you can simply do this

base64 -w0 your-cert.crt