docs(examples): add example to utilize utils
This commit is contained in:
parent
74952467e7
commit
35d3ff0216
10
examples/apply_from_directory.py
Normal file
10
examples/apply_from_directory.py
Normal file
@ -0,0 +1,10 @@
|
||||
from kubernetes import client,config,utils
|
||||
|
||||
def main():
|
||||
config.load_kube_config()
|
||||
k8s_client = client.ApiClient()
|
||||
yaml_dir = 'examples/yaml_dir/'
|
||||
utils.create_from_directory(k8s_client, yaml_dir,verbose=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
10
examples/apply_from_single_file.py
Normal file
10
examples/apply_from_single_file.py
Normal file
@ -0,0 +1,10 @@
|
||||
from kubernetes import client,config,utils
|
||||
|
||||
def main():
|
||||
config.load_kube_config()
|
||||
k8s_client = client.ApiClient()
|
||||
yaml_file = 'examples/configmap-demo-pod.yml'
|
||||
utils.create_from_yaml(k8s_client,yaml_file,verbose=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
58
examples/configmap-demo-pod.yml
Normal file
58
examples/configmap-demo-pod.yml
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: game-demo
|
||||
data:
|
||||
# property-like keys; each key maps to a simple value
|
||||
player_initial_lives: "3"
|
||||
ui_properties_file_name: "user-interface.properties"
|
||||
|
||||
# file-like keys
|
||||
game.properties: |
|
||||
enemy.types=aliens,monsters
|
||||
player.maximum-lives=5
|
||||
user-interface.properties: |
|
||||
color.good=purple
|
||||
color.bad=yellow
|
||||
allow.textmode=true
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: configmap-demo-pod
|
||||
spec:
|
||||
containers:
|
||||
- name: demo
|
||||
image: alpine
|
||||
command: ["sleep", "3600"]
|
||||
env:
|
||||
# Define the environment variable
|
||||
- name: PLAYER_INITIAL_LIVES # Notice that the case is different here
|
||||
# from the key name in the ConfigMap.
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: game-demo # The ConfigMap this value comes from.
|
||||
key: player_initial_lives # The key to fetch.
|
||||
- name: UI_PROPERTIES_FILE_NAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: game-demo
|
||||
key: ui_properties_file_name
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/config"
|
||||
readOnly: true
|
||||
volumes:
|
||||
# You set volumes at the Pod level, then mount them into containers inside that Pod
|
||||
- name: config
|
||||
configMap:
|
||||
# Provide the name of the ConfigMap you want to mount.
|
||||
name: game-demo
|
||||
# An array of keys from the ConfigMap to create as files
|
||||
items:
|
||||
- key: "game.properties"
|
||||
path: "game.properties"
|
||||
- key: "user-interface.properties"
|
||||
path: "user-interface.properties"
|
||||
18
examples/yaml_dir/config_map.yml
Normal file
18
examples/yaml_dir/config_map.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: game-demo
|
||||
data:
|
||||
# property-like keys; each key maps to a simple value
|
||||
player_initial_lives: "3"
|
||||
ui_properties_file_name: "user-interface.properties"
|
||||
|
||||
# file-like keys
|
||||
game.properties: |
|
||||
enemy.types=aliens,monsters
|
||||
player.maximum-lives=5
|
||||
user-interface.properties: |
|
||||
color.good=purple
|
||||
color.bad=yellow
|
||||
allow.textmode=true
|
||||
39
examples/yaml_dir/pod.yml
Normal file
39
examples/yaml_dir/pod.yml
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: configmap-demo-pod
|
||||
spec:
|
||||
containers:
|
||||
- name: demo
|
||||
image: alpine
|
||||
command: ["sleep", "3600"]
|
||||
env:
|
||||
# Define the environment variable
|
||||
- name: PLAYER_INITIAL_LIVES # Notice that the case is different here
|
||||
# from the key name in the ConfigMap.
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: game-demo # The ConfigMap this value comes from.
|
||||
key: player_initial_lives # The key to fetch.
|
||||
- name: UI_PROPERTIES_FILE_NAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: game-demo
|
||||
key: ui_properties_file_name
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/config"
|
||||
readOnly: true
|
||||
volumes:
|
||||
# You set volumes at the Pod level, then mount them into containers inside that Pod
|
||||
- name: config
|
||||
configMap:
|
||||
# Provide the name of the ConfigMap you want to mount.
|
||||
name: game-demo
|
||||
# An array of keys from the ConfigMap to create as files
|
||||
items:
|
||||
- key: "game.properties"
|
||||
path: "game.properties"
|
||||
- key: "user-interface.properties"
|
||||
path: "user-interface.properties"
|
||||
Loading…
Reference in New Issue
Block a user