()
| 26 | import pytz |
| 27 | |
| 28 | def main(): |
| 29 | # Creating a dynamic client |
| 30 | client = dynamic.DynamicClient( |
| 31 | api_client.ApiClient(configuration=config.load_kube_config()) |
| 32 | ) |
| 33 | |
| 34 | # fetching the deployment api |
| 35 | api = client.resources.get(api_version="apps/v1", kind="Deployment") |
| 36 | |
| 37 | name = "nginx-deployment" |
| 38 | |
| 39 | deployment_manifest = { |
| 40 | "apiVersion": "apps/v1", |
| 41 | "kind": "Deployment", |
| 42 | "metadata": {"labels": {"app": "nginx"}, "name": name}, |
| 43 | "spec": { |
| 44 | "replicas": 3, |
| 45 | "selector": {"matchLabels": {"app": "nginx"}}, |
| 46 | "template": { |
| 47 | "metadata": {"labels": {"app": "nginx"}}, |
| 48 | "spec": { |
| 49 | "containers": [ |
| 50 | { |
| 51 | "name": "nginx", |
| 52 | "image": "nginx:1.14.2", |
| 53 | "ports": [{"containerPort": 80}], |
| 54 | } |
| 55 | ] |
| 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | # Creating deployment `nginx-deployment` in the `default` namespace |
| 62 | |
| 63 | deployment = api.create(body=deployment_manifest, namespace="default") |
| 64 | |
| 65 | print("\n[INFO] deployment `nginx-deployment` created\n") |
| 66 | |
| 67 | # Listing deployment `nginx-deployment` in the `default` namespace |
| 68 | |
| 69 | deployment_created = api.get(name=name, namespace="default") |
| 70 | |
| 71 | print("%s\t%s\t\t\t%s\t%s" % ("NAMESPACE", "NAME", "REVISION", "RESTARTED-AT")) |
| 72 | print( |
| 73 | "%s\t\t%s\t%s\t\t%s\n" |
| 74 | % ( |
| 75 | deployment_created.metadata.namespace, |
| 76 | deployment_created.metadata.name, |
| 77 | deployment_created.metadata.annotations, |
| 78 | deployment_created.spec.template.metadata.annotations, |
| 79 | ) |
| 80 | ) |
| 81 | |
| 82 | # Patching the `spec.template.metadata` section to add `kubectl.kubernetes.io/restartedAt` annotation |
| 83 | # In order to perform a rolling restart on the deployment `nginx-deployment` |
| 84 | |
| 85 | deployment_manifest["spec"]["template"]["metadata"] = { |
no test coverage detected