CKAD Speed Tip

As I prepare for the Certified Kubernetes Application Developer exam, I’m looking for every possible way to shave time off the tasks at hand. One of the things that’s annoyed me when trying to move quickly from task to task is the delay in waiting for resources to be killed off.

One of the things you need to take into consideration is that Kubernetes resources have a default grace period (30 seconds).

Let’s take a look at the time it takes (your numbers will vary) to kill your average pod. We’ll use the time command to capture the numbers. In this example, I’ve created a simple pod running nginx. I’m also efficient and I have kubectl aliased to k.

$ time k delete po nginx
pod "nginx" deleted
real    0m13.416s
user    0m0.080s
sys    0m0.008s

Now let’s run the same command using the --now flag to tell kubectl that we want to set the grace period to 1.

$ time k delete po nginx --now
pod "nginx" deleted
real    0m2.012s
user    0m0.080s
sys    0m0.000s

In this example (and several other tests), I was able to reduce the time by 10 or more seconds each run. Now, if you’re really in a hurry, and don’t care about waiting at all, you can take it one step further. Be forewarned (and the command will warn you as well) that Kubernetes won’t confirm that the pod was terminated and may remain running. We can set the grace period to 0 and force the deletion.

$ time k delete po nginx --grace-period=0 --force=true
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "nginx" force deleted
real 0m0.094s
user 0m0.064s
sys 0m0.020s

 

Post to Twitter

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.