forked from kubernetes-client/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_start_hook.py
More file actions
49 lines (37 loc) · 1.14 KB
/
post_start_hook.py
File metadata and controls
49 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Example for Post Start Hook """
from kubernetes import client, config
# Fetching and loading Kubernetes Information
config.load_kube_config()
extension = client.ExtensionsV1beta1Api()
# Container
container = client.V1Container(
name="hooktest",
image="nginx:1.7.9",
image_pull_policy="IfNotPresent",
ports=[client.V1ContainerPort(container_port=80)],
lifecycle=client.V1Lifecycle(
post_start=client.V1Handler(
_exec=client.V1ExecAction(command=["touch kube-test.txt"])
)
),
)
# Template
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "hooktest"}),
spec=client.V1PodSpec(containers=[container]),
)
# Spec
spec = client.ExtensionsV1beta1DeploymentSpec(replicas=1, template=template)
# Deployment
deployment = client.ExtensionsV1beta1Deployment(
api_version="extensions/v1beta1",
kind="Deployment",
metadata=client.V1ObjectMeta(name="hooktest-deployment"),
spec=spec,
)
# Creation of the Deployment in specified namespace
extension.create_namespaced_deployment(
namespace="kube-client",
body=deployment)
if __name__ == "__main__":
main()