MCPcopy Index your code
hub / github.com/kubernetes-client/python / main

Function main

examples/dynamic-client/replication_controller.py:23–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21
22
23def main():
24 # Creating a dynamic client
25 client = dynamic.DynamicClient(
26 api_client.ApiClient(configuration=config.load_kube_config())
27 )
28
29 # fetching the replication controller api
30 api = client.resources.get(api_version="v1", kind="ReplicationController")
31
32 name = "frontend-replication-controller"
33
34 replication_controller_manifest = {
35 "apiVersion": "v1",
36 "kind": "ReplicationController",
37 "metadata": {"labels": {"name": name}, "name": name},
38 "spec": {
39 "replicas": 2,
40 "selector": {"name": name},
41 "template": {
42 "metadata": {"labels": {"name": name}},
43 "spec": {
44 "containers": [
45 {
46 "image": "nginx",
47 "name": "nginx",
48 "ports": [{"containerPort": 80, "protocol": "TCP"}],
49 }
50 ]
51 },
52 },
53 },
54 }
55
56 # Creating replication-controller `frontend-replication-controller` in the `default` namespace
57 replication_controller = api.create(
58 body=replication_controller_manifest, namespace="default"
59 )
60
61 print("\n[INFO] replication-controller `frontend-replication-controller` created\n")
62
63 # Listing replication-controllers in the `default` namespace
64 replication_controller_created = api.get(name=name, namespace="default")
65
66 print("%s\t%s\t\t\t\t\t%s" % ("NAMESPACE", "NAME", "REPLICAS"))
67 print(
68 "%s\t\t%s\t\t%s\n"
69 % (
70 replication_controller_created.metadata.namespace,
71 replication_controller_created.metadata.name,
72 replication_controller_created.spec.replicas,
73 )
74 )
75
76 # Deleting replication-controller `frontend-service` from the `default` namespace
77
78 replication_controller_deleted = api.delete(name=name, body={}, namespace="default")
79
80 print("[INFO] replication-controller `frontend-replication-controller` deleted\n")

Callers 1

Calls 3

getMethod · 0.45
createMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected