<p>I could get the kubectl working for creating configmap with a set of files with below command </p>

<pre><code>kubectl create configmap configmap2 --from-file foldername
</code></pre>

<p>where foldername contains files with keys and values</p>

<p>Now I want to create a K8s config map with the same folder using Java. I dont want to use any libraries. Is there any way I can achieve this?</p>

vidya k.s.
<p>Yes you can do that but it is not that easy - you will have to:</p>

<ul>
<li>List all files (you can use <code>java.nio.file.Files</code>)</li>
<li>Create base64 representation of the files (use <code>java.util.Base64</code> for this)</li>
<li><p>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:</p>

<pre><code>kubectl create configmap configmap2 --from-file foldername --dry-run -o json
</code></pre></li>
<li><p>Post that to the Kubernetes API Server with the correct authentication (using the new <a href="https://openjdk.java.net/groups/net/httpclient/intro.html" rel="nofollow noreferrer">HTTP client</a>)</p></li>
</ul>

<p>It would be easier to use a Kubernetes Java client (e.g.: <a href="https://github.com/fabric8io/kubernetes-client" rel="nofollow noreferrer">fabric8io client</a>, <a href="https://github.com/kubernetes-client/java" rel="nofollow noreferrer">official Kubernetes client</a>).</p>
