<p>How can I use ConfigMap to write cluster node information to a JSON file?</p>

<p>The below gives me Node information :</p>

<pre><code>kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="Hostname")].address}'
</code></pre>

<p>How can I use Configmap to write the above output to a text file? </p>

user2405589
<p>You can save the output of command in any file.
Then use the file or data inside file to create configmap.
After creating the configmap you can mount it as a file in your deployment/pod.</p>

<p>For example:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: appname
  name: appname
  namespace: development
spec:
  selector:
    matchLabels:
      app: appname
      tier: sometier
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: appname
        tier: sometier
    spec:
      containers:
        - env:
            - name: NODE_ENV
              value: development
            - name: PORT
              value: "3000"
            - name: SOME_VAR
              value: xxx
          image: someimage
          imagePullPolicy: Always
          name: appname
          volumeMounts:
            - name: your-volume-name
              mountPath: "your/path/to/store/the/file"
              readOnly: true
      volumes:
        - name: your-volume-name
          configMap:
            name: your-configmap-name
            items:
              - key: your-filename-inside-pod
                path: your-filename-inside-pod
</code></pre>

<p>I added the following configuration in deployment:</p>

<pre><code>      volumeMounts:
        - name: your-volume-name
          mountPath: "your/path/to/store/the/file"
          readOnly: true
  volumes:
    - name: your-volume-name
      configMap:
        name: your-configmap-name
        items:
          - key: your-filename-inside-pod
            path: your-filename-inside-pod
</code></pre>

<p>To create ConfigMap from file:</p>

<pre><code>kubectl create configmap your-configmap-name --from-file=your-file-path
</code></pre>

<p>Or just create ConfigMap with the output of your command:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: your-configmap-name
  namespace: your-namespace
data:
  your-filename-inside-pod: |
    output of command
</code></pre>
