チュートリアル:Shang Silicon Valley Kubernetesチュートリアル(K8sの熟練者へのエントリー)_bilibili_bilibili
ビデオの章からのメモ:第7章サービス入力
テーマ
多くのアプリケーションは、初期化または実行時にいくつかの構成情報に依存しています。ほとんどの場合、構成パラメーターによって設定された値を調整する必要があります。ConfigMapは、Kubernetesが構成データをアプリケーションポッドに挿入するために使用するメソッドです。
構成ファイル管理センターとして理解できます
ノート
ディレクトリから作成
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu/p37_config_map# cat config_map_path/game.properties
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu/p37_config_map# cat config_map_path/ui.properties
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu/p37_config_map# kubectl describe cm jjh-test-config
Name: jjh-test-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
game.properties:
----
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
ui.properties:
----
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
BinaryData
====
Events: <none>
复制代码
ファイルから作成
$ kubectl create configmap game-config-2 --from-file=docs/user- guide/configmap/kubectl/game.properties
$ kubectl get configmaps game-config-2 -o yaml
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu/p37_config_map# kubectl create configmap jjh-test-config-fromfile --from-file=./config_map_path/game.properties
configmap/jjh-test-config-fromfile created
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu/p37_config_map# kubectl describe cm jjh-test-config-fromfile
Name: jjh-test-config-fromfile
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
game.properties:
----
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
BinaryData
====
Events: <none>
复制代码
リテラル値で作成
$ kubectl create configmap special-config --from-literal=special. how=very --from- literal=special.type=charm
$ kubectl get configmaps special-config -o yaml
复制代码
configmapの使用を練習する
環境での使用
- ポートマップのリスト
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
special.how: very
special.type: charm
---
apiVersion: v1
kind: ConfigMap
metadata:
name: env-config
namespace: default
data:
log_level: INFO
复制代码
- ポッドマニフェスト
apiVersion: v1
kind: Pod
metadata:
name: portmap-test-pod
spec:
containers:
- name: test-container
image: wangyanglinux/myapp:v1
command: [ "/bin/sh", "-c", "env" ]
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.how
- name: SPECIAL_TYPE_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.type
envFrom:
- configMapRef:
name
复制代码
- セットアップ結果を表示する
root @ jjh-k8s-demo-master:〜/ k8s_yaml / bzhan_shangguigu#kubectl logs portmap-test-pod | grep -E "SPECIAL_LEVEL_KE | SPECIAL_TYPE_KEY" SPECIAL_TYPE_KEY = charm SPECIAL_LEVEL_KEY = very
ポッドコマンドラインパラメータは
apiVersion: v1
kind: Pod
metadata:
name: portmap-test-pord-cmd
spec:
containers:
- name: test-
image: wangyanglinux/myapp:v1
command: [ "/bin/sh", "-c", "echo $(SPECIAL_LEVEL_KEY) $(SPECIAL_TYPE_KEY)" ]
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.how
- name: SPECIAL_TYPE_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.type
restartPolicy: Never
复制代码
portmapConfigはボリュームの下にマウントされています
- リソースのリスト
apiVersion: v1
kind: Pod
metadata:
name: portmap-test-pod-volume
spec:
containers:
- name: test-container
image: wangyanglinux/myapp:v1
command: [ "/bin/sh", "-c", "sleep 360; cat /etc/config/special.how" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: special-config
restartPolicy: Never
复制代码
- 適用してから、構成を確認してください
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu# kubectl apply -f p38_portmap_pod_volume.yaml
pod/portmap-test-pod-volume created
root@jjh-k8s-demo-master:~/k8s_yaml/bzhan_shangguigu# kubectl exec portmap-test-pod-volume -- cat /etc/config/special.how
very
复制代码
構成マップ構成をポッド内のファイルにエクスポートすることの利点は、約10秒の遅延でローリング更新のトリガーをサポートすることです。環境内の場合、ローリングアップデートはありません