File tree 5 files changed +135
-0
lines changed
5 files changed +135
-0
lines changed Original file line number Diff line number Diff line change
1
+ from kubernetes import client ,config ,utils
2
+
3
+ def main ():
4
+ config .load_kube_config ()
5
+ k8s_client = client .ApiClient ()
6
+ yaml_dir = 'examples/yaml_dir/'
7
+ utils .create_from_directory (k8s_client , yaml_dir ,verbose = True )
8
+
9
+ if __name__ == "__main__" :
10
+ main ()
Original file line number Diff line number Diff line change
1
+ from kubernetes import client ,config ,utils
2
+
3
+ def main ():
4
+ config .load_kube_config ()
5
+ k8s_client = client .ApiClient ()
6
+ yaml_file = 'examples/configmap-demo-pod.yml'
7
+ utils .create_from_yaml (k8s_client ,yaml_file ,verbose = True )
8
+
9
+ if __name__ == "__main__" :
10
+ main ()
Original file line number Diff line number Diff line change
1
+ ---
2
+ apiVersion : v1
3
+ kind : ConfigMap
4
+ metadata :
5
+ name : game-demo
6
+ data :
7
+ # property-like keys; each key maps to a simple value
8
+ player_initial_lives : " 3"
9
+ ui_properties_file_name : " user-interface.properties"
10
+
11
+ # file-like keys
12
+ game.properties : |
13
+ enemy.types=aliens,monsters
14
+ player.maximum-lives=5
15
+ user-interface.properties : |
16
+ color.good=purple
17
+ color.bad=yellow
18
+ allow.textmode=true
19
+
20
+ ---
21
+ apiVersion : v1
22
+ kind : Pod
23
+ metadata :
24
+ name : configmap-demo-pod
25
+ spec :
26
+ containers :
27
+ - name : demo
28
+ image : alpine
29
+ command : ["sleep", "3600"]
30
+ env :
31
+ # Define the environment variable
32
+ - name : PLAYER_INITIAL_LIVES # Notice that the case is different here
33
+ # from the key name in the ConfigMap.
34
+ valueFrom :
35
+ configMapKeyRef :
36
+ name : game-demo # The ConfigMap this value comes from.
37
+ key : player_initial_lives # The key to fetch.
38
+ - name : UI_PROPERTIES_FILE_NAME
39
+ valueFrom :
40
+ configMapKeyRef :
41
+ name : game-demo
42
+ key : ui_properties_file_name
43
+ volumeMounts :
44
+ - name : config
45
+ mountPath : " /config"
46
+ readOnly : true
47
+ volumes :
48
+ # You set volumes at the Pod level, then mount them into containers inside that Pod
49
+ - name : config
50
+ configMap :
51
+ # Provide the name of the ConfigMap you want to mount.
52
+ name : game-demo
53
+ # An array of keys from the ConfigMap to create as files
54
+ items :
55
+ - key : " game.properties"
56
+ path : " game.properties"
57
+ - key : " user-interface.properties"
58
+ path : " user-interface.properties"
Original file line number Diff line number Diff line change
1
+ ---
2
+ apiVersion : v1
3
+ kind : ConfigMap
4
+ metadata :
5
+ name : game-demo
6
+ data :
7
+ # property-like keys; each key maps to a simple value
8
+ player_initial_lives : " 3"
9
+ ui_properties_file_name : " user-interface.properties"
10
+
11
+ # file-like keys
12
+ game.properties : |
13
+ enemy.types=aliens,monsters
14
+ player.maximum-lives=5
15
+ user-interface.properties : |
16
+ color.good=purple
17
+ color.bad=yellow
18
+ allow.textmode=true
Original file line number Diff line number Diff line change
1
+ ---
2
+ apiVersion : v1
3
+ kind : Pod
4
+ metadata :
5
+ name : configmap-demo-pod
6
+ spec :
7
+ containers :
8
+ - name : demo
9
+ image : alpine
10
+ command : ["sleep", "3600"]
11
+ env :
12
+ # Define the environment variable
13
+ - name : PLAYER_INITIAL_LIVES # Notice that the case is different here
14
+ # from the key name in the ConfigMap.
15
+ valueFrom :
16
+ configMapKeyRef :
17
+ name : game-demo # The ConfigMap this value comes from.
18
+ key : player_initial_lives # The key to fetch.
19
+ - name : UI_PROPERTIES_FILE_NAME
20
+ valueFrom :
21
+ configMapKeyRef :
22
+ name : game-demo
23
+ key : ui_properties_file_name
24
+ volumeMounts :
25
+ - name : config
26
+ mountPath : " /config"
27
+ readOnly : true
28
+ volumes :
29
+ # You set volumes at the Pod level, then mount them into containers inside that Pod
30
+ - name : config
31
+ configMap :
32
+ # Provide the name of the ConfigMap you want to mount.
33
+ name : game-demo
34
+ # An array of keys from the ConfigMap to create as files
35
+ items :
36
+ - key : " game.properties"
37
+ path : " game.properties"
38
+ - key : " user-interface.properties"
39
+ path : " user-interface.properties"
You can’t perform that action at this time.
0 commit comments