File to ConfigMap

1 개요[ | ]

File to ConfigMap
file2cm.sh
cat <<'EOF' > file2cm.sh
if [ -z "$1" ]; then echo "Error: no file"; exit; fi
if [ -z "$2" ]; then NS=default; else NS=$2; fi
if [ -z "$3" ]; then CM="cm-$(echo $1 | sed 's/\./-/g')"; else CM=$3; fi
if [ -z "$4" ]; then YAML="${NS}_${CM}.yaml"; else YAML=$4; fi
kubectl create configmap $CM -n $NS --from-file $1 --dry-run=client -oyaml | sed 's/\\\\n/\\n/g' > $YAML
echo $YAML created.
EOF
chmod +x file2cm.sh
tester@localhost:~$ cat file2cm.sh 
if [ -z "$1" ]; then echo "Error: no file"; exit; fi
if [ -z "$2" ]; then NS=default; else NS=$2; fi
if [ -z "$3" ]; then CM="cm-$(echo $1 | sed 's/\./-/g')"; else CM=$3; fi
if [ -z "$4" ]; then YAML="${NS}_${CM}.yaml"; else YAML=$4; fi
kubectl create configmap $CM -n $NS --from-file $1 --dry-run=client -oyaml | sed 's/\\\\n/\\n/g' > $YAML
echo $YAML created.

2 실행예시[ | ]

tester@localhost:~$ cat <<'EOF' > entrypoint.sh
> echo Hello
> sleep 3600
> EOF
tester@localhost:~$ cat entrypoint.sh 
echo Hello
sleep 3600
tester@localhost:~$ ./file2cm.sh entrypoint.sh 
default_cm-entrypoint-sh.yaml created.
tester@localhost:~$ cat default_cm-entrypoint-sh.yaml 
apiVersion: v1
data:
  entrypoint.sh: |
    echo Hello
    sleep 3600
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: cm-entrypoint-sh
  namespace: default
tester@localhost:~$ ./file2cm.sh entrypoint.sh ns1
ns1_cm-entrypoint-sh.yaml created.
tester@localhost:~$ cat ns1_cm-entrypoint-sh.yaml
apiVersion: v1
data:
  entrypoint.sh: |
    echo Hello
    sleep 3600
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: cm-entrypoint-sh
  namespace: ns1
tester@localhost:~$ ./file2cm.sh entrypoint.sh ns1 cm1
ns1_cm1.yaml created.
tester@localhost:~$ cat ns1_cm1.yaml
apiVersion: v1
data:
  entrypoint.sh: |
    echo Hello
    sleep 3600
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: cm1
  namespace: ns1
tester@localhost:~$ ./file2cm.sh entrypoint.sh ns1 cm1 myconfigmap.yaml
myconfigmap.yaml created.
tester@localhost:~$ cat myconfigmap.yaml
apiVersion: v1
data:
  entrypoint.sh: |
    echo Hello
    sleep 3600
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: cm1
  namespace: ns1

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}