kubernetes pod cold start time

161 Views Asked by At

I encountered a strange phenomenon when recording the startup time of pods in Kubernetes. The startup time was similar to a sine function: long-short-long-short.....

enter image description here

Scenario: Two virtual machines running Ubuntu 20 wiht 8G ram, with one Kubernetes control node and one worker node deployed, using Docker as the underlying container, The container images are downloaded to the local in advance.

WorkFlow: Every 6 seconds, a pod is started with only one container: python-3.7. The container then calculates the Fibonacci sequence and after that, the pod is deleted.

The Kubernetes Python API was used for control, generating pods and recording their startup time.

def start(Corev1,podbody_fbi):
    start = time.time()
    reate_pod_response_fbi = Corev1.create_namespaced_pod("dev",podbody_fbi)
    watch = kubernetes.watch.Watch()
    for event in watch.stream(func=Corev1.list_namespaced_pod,namespace="dev"):

        if event["object"].metadata.name == podbody_fbi["metadata"]['name'] and  event["object"].status.phase == "Running":
            print(event["object"].metadata.name + "running"  )
            watch.stop()
            end = time.time()
            return start,end

I'm not sure where the problem lies, whether it's with Docker itself or with using Python to record the startup time.

I'm wondering if there's a way to make the startup time of the containers more stable.

0

There are 0 best solutions below