Skip to main content

ConfigMaps

Managing Binary Data with Kubernetes ConfigMaps

Kubernetes ConfigMaps are a powerful way to manage configuration data for your applications. While they're often used for plain text configurations, they can also store binary data.

This capability is especially useful for non-text configurations such as certificates, images, or any other binary data your application might need.

In this blog post, we'll explore how to use ConfigMaps to store binary data with a practical example.

What are Binary Files?

Binary files are files that contain data in a format that is not human-readable.

For example,

  1. Certificates: .crt, .key
  2. Compiled Code Libraries: .dll, .so

Create a Sample Binary File

For this example, let's create a simple binary file for demo purposes.

echo "AAECAwQFBgcICQoLDA0ODwSDFASDFASDFASD"> demo.bin

Using the Binary File in a ConfigMap

Here's how you can incorporate this binary file into a Kubernetes ConfigMap:

Step 1: Base64 Encode the Binary File:

Important Note: The binary file has to be first encoded in base64 format.
base64 demo.bin > base64_demo.txt

Step 2: Create the ConfigMap YAML with base64 content.

First get the content of base64_demo.txt

cat base64_demo.txt

Now use the output in the Configmap as given below.

apiVersion: v1
kind: ConfigMap
metadata:
  name: binary-configmap
binaryData:
  demo.bin: AAECAwQFBgcICQoLDA0ODw==

Step 3: Apply the coonfigmap

kubectl apply -f configmap.yaml

Step 4: Validate the binary data configmap.

kubectl describe cm binary-configmap

In the output you will see the Binary Data section with the demo.bin file.

Name:         binary-configmap
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====

BinaryData
====
demo.bin: 16 bytes

Events:  <none>