Commit db69f3ea authored by Santhosh Kumar's avatar Santhosh Kumar

cleanup code

parent bc8339a3
...@@ -10,3 +10,17 @@ sudo kubeadm token create --print-join-command ...@@ -10,3 +10,17 @@ sudo kubeadm token create --print-join-command
# Run this command to join. # Run this command to join.
kubectl exec -it test-f7bbc6dcb-kzdsw -- /bin/bash
kubectl describe HorizontalPodAutoscaler test-hpa
kubectl get pods -n kube-system
kubectl logs metrics-server-8857d6b7c-59xbb -n kube-system
kubectl delete pod metrics-server-8857d6b7c-59xbb -n kube-system
http://localhost:5000/memory?size=1G
kubectl scale deployment test --replicas=1
...@@ -111,6 +111,36 @@ def rollback_deployment(function_name): ...@@ -111,6 +111,36 @@ def rollback_deployment(function_name):
print("Rolling back deployment...") print("Rolling back deployment...")
apps_api.rollback_namespaced_deployment(name=function_name, namespace="default") apps_api.rollback_namespaced_deployment(name=function_name, namespace="default")
def manual_scale():
deployment_name = input("Enter the deployment name: ")
replicas = int(input("Enter the number of replicas to scale to: "))
try:
# Get current replicas
deployment = apps_api.read_namespaced_deployment(name=deployment_name, namespace="default")
current_replicas = deployment.spec.replicas
# Determine scaling action
if replicas > current_replicas:
action = "up"
elif replicas < current_replicas:
action = "down"
else:
action = "unchanged"
# Scale deployment
apps_api.patch_namespaced_deployment_scale(
name=deployment_name,
namespace="default",
body={"spec": {"replicas": replicas}}
)
print(f"Deployment '{deployment_name}' scaled {action} to {replicas} replicas successfully.")
except ApiException as e:
if e.status == 404:
print(f"Deployment '{deployment_name}' does not exist.")
else:
print(f"Error scaling deployment '{deployment_name}': {e}")
def scale_deployment(): def scale_deployment():
function_name = input("Enter the function name: ") function_name = input("Enter the function name: ")
min_replicas = int(input("Enter min replicas: ")) min_replicas = int(input("Enter min replicas: "))
...@@ -262,6 +292,8 @@ def get_deployment_info(): ...@@ -262,6 +292,8 @@ def get_deployment_info():
for deployment in deployments: for deployment in deployments:
deployment_name = deployment.metadata.name deployment_name = deployment.metadata.name
replicas = deployment.status.replicas replicas = deployment.status.replicas
if replicas == None:
replicas = 0
# Get resource limits # Get resource limits
limits = deployment.spec.template.spec.containers[0].resources.limits limits = deployment.spec.template.spec.containers[0].resources.limits
...@@ -517,17 +549,18 @@ def select_operation(): ...@@ -517,17 +549,18 @@ def select_operation():
print("6. Expose Service") print("6. Expose Service")
print("7. Get Function Logs") print("7. Get Function Logs")
print("8. Get resource usage") print("8. Get resource usage")
print("9. Misc functions") print("9. Manual Scaling ")
print("10. Exit") print("10. Misc functions")
print("11. Exit")
while True: while True:
try: try:
choice = int(input("Enter your choice (1-10): ")) choice = int(input("Enter your choice (1-11): "))
if 1 <= choice <= 10: if 1 <= choice <= 11:
return choice return choice
else: else:
print(choice) print(choice)
print("Invalid choice. Please enter a number between 1 and 10.") print("Invalid choice. Please enter a number between 1 and 11.")
except ValueError: except ValueError:
print("Invalid input. Please enter a number.") print("Invalid input. Please enter a number.")
...@@ -570,7 +603,11 @@ if __name__ == "__main__": ...@@ -570,7 +603,11 @@ if __name__ == "__main__":
elif choice == 9: elif choice == 9:
print("Resource Information ...") print("Resource Information ...")
# Call function to expose service # Call function to expose service
misc_info() manual_scale()
elif choice == 10: elif choice == 10:
print("Resource Information ...")
# Call function to expose service
misc_info()
elif choice == 11:
print("Exiting...") print("Exiting...")
break break
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment