Created
July 28, 2026 12:51
-
-
Save agoose77/251530816715889aeba256ad200bc1b8 to your computer and use it in GitHub Desktop.
Deployment controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import argparse | |
| from kubernetes import client, config | |
| from kubernetes.client.exceptions import NotFoundException | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("replicas", type=int) | |
| parser.add_argument("--deployment", default="node-placeholder") | |
| parser.add_argument("-n", "--namespace", default="default") | |
| args = parser.parse_args() | |
| # Configs can be set in Configuration class directly or using helper utility | |
| config.load_kube_config() | |
| with client.ApiClient() as api_client: | |
| api_instance = client.AppsV1Api(api_client) | |
| print("Finding deployment") | |
| try: | |
| scale = api_instance.read_namespaced_deployment_scale( | |
| args.deployment, args.namespace | |
| ) | |
| except client.NotFoundException: | |
| raise SystemExit(1) | |
| print(f"Scaling from {scale.spec.replicas} to {args.replicas} replicas") | |
| try: | |
| deployment = api_instance.patch_namespaced_deployment_scale( | |
| args.deployment, args.namespace, {"spec": {"replicas": args.replicas}} | |
| ) | |
| except NotFoundException: | |
| raise SystemExit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment