DireRaven
DireRaven

Reputation: 69

YAML code to create a configmap with a particular file (.js/.sh)

What will be the equivalent ConfigMap YAML code for the following command line?

kubectl create configmap mongo-initdb --from-file=init-mongo.js

Upvotes: 0

Views: 112

Answers (3)

Ravindra Singh
Ravindra Singh

Reputation: 1

Create the configmap from a file.
Just create a sample file like ui.properties
example:
cat ui.properties
1. name=x
2. rollno=y
    
Command to create a configmap from above file
kubectl create configmap ui-configmap --from-file=ui.properties

Verify the data.
kubectl get configmap ui-configmap  -o yaml

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: <>
  name: ui-configmap
  namespace: default
data:
  name: x
  role: y

Upvotes: 0

Harsh Manvar
Harsh Manvar

Reputation: 30160

You can use the command as suggested by Mo Xue, however here is YAML,

Example :

apiVersion: v1
kind: ConfigMap
metadata:
  name: mongo-initdb
data:
  init-mongo.js: |
    <Content> 

Read more about : https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-directories

Upvotes: 0

Mo Xue
Mo Xue

Reputation: 36

There is actually a kubectl command that lets you get the generated yaml for a created config map. In your case:

kubectl get configmaps mongo-initdb -o yaml

Upvotes: 1

Related Questions