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

 

Clearing Unnamed Docker Images

I’ve been playing around with Docker a lot lately and the number of images on my host keeps climbing. In doing so, I’ve managed to end up with a number of images which weren’t properly named/tagged and I really have no idea what they’re for at this point. Oh, sure, I could always just do a [shell]docker inspect image_id[/shell] on the image and see what it is, but I’m lazy. It’s easier just to get rid of them. 🙂

So if I use ‘docker images’ to see what I have available you can see I’ve got a number of images in the state I describe.

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
runlevl4/couch                     latest              c0d143528267        19 hours ago        573MB
runlevl4/openjdk                   latest              1a04169be1f0        20 hours ago        738MB
runlevl4/alpine-wso2               latest              382b74b4df93        11 days ago         757MB
<none>                             <none>              2fbbf4f7f2ae        11 days ago         757MB
runlevl4/alpine-wso2               v1                  581ac302a5e7        11 days ago         757MB
<none>                             <none>              3c2bd15fa447        11 days ago         757MB
centos7/nonroot                    v1                  03f554e67899        13 days ago         197MB
<none>                             <none>              e876350b9c92        13 days ago         197MB

Here’s a quick and easy way to get rid of them. First, we’ll do a dry run and just return the images we want to purge.

docker images | grep "<none>" | tr -s " " | cut -d " " -f 3

docker images – returns all the images on our host
grep “” – reduces the results to just those we’re after
tr -s ” ” – this is a fun one. the -s argument tells tr to replace all of the spaces with a single space
cut -d ” ” -f 3 – we use cut to reduce the results to just the image id. -d sets the delimiter as a single space and -f grabs the third field

Let’s see some examples as we build the command out.

docker images | grep "<none>"
<none>                             <none>              2fbbf4f7f2ae        11 days ago         757MB
<none>                             <none>              3c2bd15fa447        11 days ago         757MB
<none>                             <none>              e876350b9c92        13 days ago         197MB

Now we throw in the tr command.

docker images | grep "<none>" | tr -s " "
<none> <none> 2fbbf4f7f2ae 11 days ago 757MB
<none> <none> 3c2bd15fa447 11 days ago 757MB
<none> <none> e876350b9c92 13 days ago 197MB

And finally, we return just the image id.

docker images | grep "<none>" | tr -s " " | cut -d " " -f 3
2fbbf4f7f2ae
3c2bd15fa447
e876350b9c92

Now that we know our command is working, we can pass it as an argument to the [shell]docker rmi[/shell] command. ‘docker rmi’ is the CLI command to remove one or more Docker images.

docker rmi $(docker images | grep "<none>" | tr -s " " | cut -d " " -f 3)
Deleted: sha256:2fbbf4f7f2aef4d47d74a44ec32fe2cf8d3fd4650b7d216675908f3757651b21
Deleted: sha256:3c2bd15fa447d9e5ffd12e8d149147fb5dd66cb48c9f152748b42514abcaf5a1
Deleted: sha256:84243c17c3cf36e418afe44880b33490f537e91b81ef9ac78a3d345e6a7609b0
Deleted: sha256:e876350b9c92fce722c096ef989216f802b264276676219cc2f321ff279d5ba5

Now you can use [shell]docker images[/shell] again to confirm that they’re gone.

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
runlevl4/couch                     latest              c0d143528267        19 hours ago        573MB
runlevl4/openjdk                   latest              1a04169be1f0        20 hours ago        738MB
runlevl4/alpine-wso2               latest              382b74b4df93        11 days ago         757MB
runlevl4/alpine-wso2               v1                  581ac302a5e7        11 days ago         757MB
centos7/nonroot                    v1                  03f554e67899        13 days ago         197MB

WiFi, Wherefore Art Thou

So it’s been a couple of months since I replaced the keyboard on my Gazelle and I’m still digging it. There’s one other issue that I should mention that I hadn’t really worried about. I noticed the Bluetooth never worked. Since I already had a USB mouse it wasn’t a big deal until I started having other issues. Periodically I’d looked it up but never found any solid solutions. The Gazelle has a dual-purpose Intel 8260 WiFi/Bluetooth adapter and it seemed like there were issues with both the 7260 and 8260 under Linux. It also appeared that the issues were resolved in newer kernels but even upgrading to 4.6 didn’t resolve the issue. Nothing I did could even get the adapter to show up. Read More

Keyboard Trouble In Paradise

It’s been a while since I got my Gazelle laptop from System76. The matte display continues to wow me every time I turn it on. The speed with the i5 processor and my upgraded SSD makes this a screaming machine. I replaced the stock spinning drive with a 1TB Samsung 850 EVO drive which has been an absolute dream. I’m half tempted, though, to pick up an even faster m2 drive if prices come down enough. But I digress. Read More