-
以下を満たすマニフェストを作成しデプロイしてください。ConfigMapについては公式ドキュメントを参考にしてください。PodでConfigMapを環境変数として読み込む方法は公式ドキュメントを参考にしてください。
- 要件
- ConfigMap
- 以下のKey-Valueをdataとして持つ
- EP1: The Python Menace
- EP2: Attack of the Clones
- EP3: Revenge of the Sith
- EP4: A New Hoge
- EF5: The Empire Strikes Back
- EP6: Return of the Jedi
- EP7: The Force Awakens
- EP8: The Last Jedi
- EP9: The Rise of Kubernetes
- 以下のKey-Valueをdataとして持つ
- Deployment(1つ目)
- メインコンテナはshが使用できれば何でも良い
- 上記ConfigMapのKey-Valueをすべて環境変数として読み込む
- メインコンテナのコマンドは以下を指定
- command:
['/bin/sh','-c','echo "Star Wars no title ichiran \n $EP1 \n $EP2 \n $EP3 \n $EP4 \n $EP5 \n $EP6 \n $EP7 \n $EP8 \n $EP9"; sleep 3600']
- command:
- Deployment(2つ目)
- メインコンテナはshが使用できれば何でも良い
- 上記ConfigMapのKey-Valueをすべて環境変数として読み込む
- メインコンテナのコマンドは以下を指定
- command:
['/bin/sh','-c','echo "Star Wars no koukai jyun \n $EP4 \n $EP5 \n $EP6 \n $EP1 \n $EP2 \n $EP3 \n $EP7 \n $EP8 \n $EP9; sleep 3600']
- command:
- ConfigMap
【回答例】
# manifest apiVersion: v1 kind: ConfigMap metadata: name: starwars-ep data: EP1: The Python Menace EP2: Attack of the Clones EP3: Revenge of the Sith EP4: A New Hoge EF5: The Empire Strikes Back EP6: Return of the Jedi EP7: The Force Awakens EP8: The Last Jedi EP9: The Rise of Kubernetes --- apiVersion: apps/v1 kind: Deployment metadata: name: starwars-title spec: replicas: 1 selector: matchLabels: app: starwars-title template: metadata: labels: app: starwars-title spec: containers: - name: busybox image: busybox envFrom: - configMapRef: name: starwars-ep command: ['/bin/sh','-c','echo "Star Wars no title ichiran \n $EP1 \n $EP2 \n $EP3 \n $EP4 \n $EP5 \n $EP6 \n $EP7 \n $EP8 \n $EP9"; sleep 3600'] --- apiVersion: apps/v1 kind: Deployment metadata: name: starwars-koukai spec: replicas: 1 selector: matchLabels: app: starwars-koukai template: metadata: labels: app: starwars-koukai spec: containers: - name: busybox image: busybox envFrom: - configMapRef: name: starwars-ep command: ['/bin/sh','-c','echo "Star Wars no koukai jyun \n $EP4 \n $EP5 \n $EP6 \n $EP1 \n $EP2 \n $EP3 \n $EP7 \n $EP8 \n $EP9"; sleep 3600']
# 実行結果 kubectl apply -f configmap-env.yaml configmap/starwars-ep created eployment.apps/starwars-title created eployment.apps/starwars-koukai created - 要件
-
各Deploymentで展開したPodのログを表示してください。
【回答例】
# 実行結果 $ kubectl logs starwars-title-8749d55ff-78ffs Star Wars no title ichiran \n The Python Menace \n Attack of the Clones \n Revenge of the Sith \n A New Hoge \n \n Return of the Jedi \n The Force Awakens \n The Last Jedi \n The Rise of Kubernetes $ kubectl logs starwars-koukai-f6dff5457-zjfkt Star Wars no koukai jyun \n A New Hoge \n \n Return of the Jedi \n The Python Menace \n Attack of the Clones \n Revenge of the Sith \n The Force Awakens \n The Last Jedi \n The Rise of Kubernetes
-
ConfigMapの値の誤りを修正し再デプロイしてください。なお、正しいvalueは参考サイトなどを参照してください。
(誤りは2か所)【回答例】
# manifest apiVersion: v1 kind: ConfigMap metadata: name: starwars-ep data: EP1: The Phantom Menace EP2: Attack of the Clones EP3: Revenge of the Sith EP4: A New Hope EF5: The Empire Strikes Back EP6: Return of the Jedi EP7: The Force Awakens EP8: The Last Jedi EP9: The Rise of Skywalker --- apiVersion: apps/v1 kind: Deployment metadata: name: starwars-title spec: replicas: 1 selector: matchLabels: app: starwars-title template: metadata: labels: app: starwars-title spec: containers: - name: busybox image: busybox envFrom: - configMapRef: name: starwars-ep command: ['/bin/sh','-c','echo "Star Wars no title ichiran \n $EP1 \n $EP2 \n $EP3 \n $EP4 \n $EP5 \n $EP6 \n $EP7 \n $EP8 \n $EP9"; sleep 3600'] --- apiVersion: apps/v1 kind: Deployment metadata: name: starwars-koukai spec: replicas: 1 selector: matchLabels: app: starwars-koukai template: metadata: labels: app: starwars-koukai spec: containers: - name: busybox image: busybox envFrom: - configMapRef: name: starwars-ep command: ['/bin/sh','-c','echo "Star Wars no koukai jyun \n $EP4 \n $EP5 \n $EP6 \n $EP1 \n $EP2 \n $EP3 \n $EP7 \n $EP8 \n $EP9"; sleep 3600']
# 実行結果 kubectl apply -f configmap-env.yaml configmap/starwars-ep configured deployment.apps/starwars-title unchanged deployment.apps/starwars-koukai unchanged -
各Deploymentで展開したPodのログを表示してください。表示が
変わらないことを確認してください。【回答例】
# 実行結果 $ kubectl logs starwars-title-8749d55ff-78ffs Star Wars no title ichiran \n The Python Menace \n Attack of the Clones \n Revenge of the Sith \n A New Hoge \n \n Return of the Jedi \n The Force Awakens \n The Last Jedi \n The Rise of Kubernetes $ kubectl logs starwars-koukai-f6dff5457-zjfkt Star Wars no koukai jyun \n A New Hoge \n \n Return of the Jedi \n The Python Menace \n Attack of the Clones \n Revenge of the Sith \n The Force Awakens \n The Last Jedi \n The Rise of Kubernetes
-
各Deploymentで展開したPodのログを削除し、セルフ・ヒーリングさせてください。
【回答例】
# 実行結果 $ kubectl delete pod --all pod "starwars-koukai-f6dff5457-zjfkt" deleted pod "starwars-title-8749d55ff-78ff" deleted
-
各Deploymentで展開したPodのログを表示してください。表示が変わることを確認してください。
【回答例】
# 実行結果 $ kubectl logs starwars-title-8749d55ff-mplsz Star Wars no title ichiran \n The Phantom Menace \n Attack of the Clones \n Revenge of the Sith \n A New Hope \n \n Return of the Jedi \n The Force Awakens \n The Last Jedi \n The Rise of Skywalker $ kubectl logs starwars-koukai-f6dff5457-rx575 Star Wars no koukai jyun \n A New Hope \n \n Return of the Jedi \n The Phantom Menace \n Attack of the Clones \n Revenge of the Sith \n The Force Awakens \n The Last Jedi \n The Rise of Skywalker
-
作成したリソースを削除してください。
【回答例】
# 実行結果 # kubectl delete -f configmap-env.yaml configmap "starwars-ep" deleted deployment.apps "starwars-title" deleted deployment.apps "starwars-koukai" deleted