Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
stress-k8s.py
from kubernetes import client, config
import time
deployment_name = 'ddd'
def scale_deployment(api_instance, namespace, name, replicas, scale):
scale.spec.replicas = replicas
result = api_instance.patch_namespaced_deployment(namespace='default', name=name, body=scale)
def read_deployment_available(api_instance, namespace, name):
result = api_instance.read_namespaced_deployment_status(namespace=namespace, name=name)
return result.status.available_replicas
def wait_for_num(api_instance, namespace, name, goal):
start = time.time()
while 1:
result = read_deployment_available(api_instance, namespace, name)
if result == None:
result = 0
if abs(result-goal) > 0:
print 'not all ready:', result, goal
time.sleep(5)
else:
break
spend = time.time() - start
print 'spend:', spend
def main():
stress_num = 30000
config.load_kube_config("/home/ubuntu/.kube/config")
ba = client.ExtensionsV1beta1Api()
while 1:
scale = ba.read_namespaced_deployment_scale(namespace='default',name=deployment_name)
scale_deployment(ba, 'default', deployment_name, stress_num, scale)
wait_for_num(ba, 'default', deployment_name, stress_num)
scale = ba.read_namespaced_deployment_scale(namespace='default',name=deployment_name)
scale_deployment(ba, 'default', deployment_name, 0, scale)
wait_for_num(ba, 'default', deployment_name, 0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.