Kubernetes API for configmap
Yes you can do that but it is not that easy - you will have to:
- List all files (you can use
java.nio.file.Files
) - Create base64 representation of the files (use
java.util.Base64
for this) Create a JSON representing the files and the meta-data (you will have to use String concatenation for this). The JSON should look like the output of:
kubectl create configmap configmap2 --from-file foldername --dry-run -o json
Post that to the Kubernetes API Server with the correct authentication (using the new HTTP client)
It would be easier to use a Kubernetes Java client (e.g.: fabric8io client, official Kubernetes client).
Here is the API request that you have to make to the Kubernetes API server to create a ConfigMap:
The data must be a ConfigMap JSON object as specified here.
If you don't use a library, you must also include the correct credentials in the request, which is usually a token (Authorization: Bearer <token>
) or a certificate.
Tip:
You can use kubectl create configmap -v 10 configmap2 --from-file foldername
(note -v 10
) to see the exact HTTP request that kubectl makes to the API server.