How to avoid other pods from being scheduled on your node in Kubernetes

Taints on nodes repel pods. Tolerations on pods let them ignore specific taints. Together they give you control over scheduling. Taint effects NoSchedule — pods without a matching toleration won’t be scheduled on the node. PreferNoSchedule — the scheduler avoids the node but will use it if there’s nowhere else. NoExecute — pods without a matching toleration are evicted and won’t be rescheduled there. Applying a taint kubectl taint nodes node1 type=db:NoSchedule This prevents any pod from being scheduled on node1 unless it has a toleration for type=db. ...

13 July 2023 · 1 min · 149 words · Shafiq Alibhai

Kubernetes Tolerations

Taints and tolerations work together to control which pods land on which nodes. Taints go on nodes and repel pods. Tolerations go on pods and let them ignore specific taints. Taint effects There are three effects: NoSchedule — pods without a matching toleration won’t be scheduled on the node. Existing pods are unaffected. PreferNoSchedule — the scheduler avoids the node but will use it if there’s nowhere else. NoExecute — pods without a matching toleration are evicted from the node and won’t be rescheduled there. Applying taints # Add a taint kubectl taint nodes node1 example-key=example-value:NoSchedule # Remove a taint kubectl taint nodes node1 example-key=example-value:NoSchedule- # Multiple taints at once kubectl taint nodes node1 key1=value1:NoSchedule key2=value2:PreferNoSchedule View taints on a node: ...

11 July 2023 · 2 min · 248 words · Shafiq Alibhai

Remove lines matching a pattern from files recursively in Linux

find . -name "*.md" -type f -exec sed -i '/pattern/d' {} \; This one-liner walks the directory tree, finds every .md file, and strips out any line that matches the given pattern. The sed -i edits each file in place, and the {} gets swapped out for whatever path find hands it. Breaking it down find . -name "*.md" -type f does the walking. The -type f bit is important – without it, find would also match directories and pass them to sed, which would error out. The -exec ... \; at the end runs the command for each file individually. ...

27 April 2023 · 2 min · 299 words · Shafiq Alibhai

Installing PhantomJS on Ubuntu 22.10

PhantomJS is a headless browser, which means it runs without a graphical interface and lets you automate web page interactions through scripting. I needed it for some automated testing at work and ran into a few things worth writing down, mostly because half the guides out there are either outdated or assume you already know what you’re doing. The version we’re installing is 2.1.1, which is the last release. The project has been unmaintained since 2017, but it still does what it needs to do for basic scraping and screenshot tasks. ...

27 April 2023 · 1 min · 199 words · Shafiq Alibhai

Deleting files by content match in Linux

There are two ways to interpret this question, and the answer changes completely depending on which one you mean. Deleting files by filename If you want to nuke every file whose name contains a particular string: find . -type f -name '*string*' -delete The -type f keeps it from touching directories. The -delete flag removes whatever find matches. Simple enough. A word of caution: test without -delete first. Run the same command and replace it with -print to see what would actually get deleted. I’ve lost files to typos in wildcard patterns more times than I care to admit. ...

27 April 2023 · 2 min · 305 words · Shafiq Alibhai

How to Resolve "Cannot Unregister the Machine While It Is Locked" Error in Vagrant

Running vagrant destroy sometimes fails with: VBoxManage: error: Cannot unregister the machine 'CnC_default_1643660523119_45689' while it is locked The VM is locked because a VirtualBox process is still holding onto it. Kill the headless process and try again: killall -9 VBoxHeadless && vagrant destroy killall -9 VBoxHeadless force-kills any running VirtualBox headless instances. The && runs vagrant destroy only if that succeeds.

1 February 2022 · 1 min · 61 words · Shafiq Alibhai

Grabbing an SSL certificate from a remote server

There are moments when you need to inspect the certificate a remote server is presenting – maybe it’s expired and you’re trying to work out why things are breaking, or maybe you need the raw certificate data for some other reason and don’t have access to the server’s configuration. The quickest way is with openssl s_client: openssl s_client -connect {HOSTNAME}:{PORT} -showcerts Replace {HOSTNAME} with the server address and {PORT} with the port (usually 443 for HTTPS). The -showcerts flag dumps the full certificate chain rather than just the leaf certificate. ...

15 June 2021 · 1 min · 149 words · Shafiq Alibhai

Replace all dots in filenames except the extension on Linux

Had a directory full of files with dots in the names and needed them all cleaned up. Something like my.report.final.pdf should become my_report_final.pdf, not my_report_final..pdf or worse. This one-liner does the job: for f in *; do pre="${f%.*}"; suf="${f##*.}"; mv -i -- "$f" "${pre//./_}.${suf}"; done Here’s what each part does. ${f%.*} strips everything from the last dot onwards, giving you the filename without its extension. ${f##*.} grabs just the extension by stripping everything up to and including the final dot. Then ${pre//./_} replaces every dot in the base name with an underscore. ...

21 January 2021 · 1 min · 146 words · Shafiq Alibhai

Count directories in the current folder with a one-liner

A common question that comes up when you’re first getting comfortable with the command line: how do you count just the directories in your current folder? The quick answer is: ls -1 | wc -l This pipes a one-per-line listing of everything in the current directory into wc -l, which counts lines. Simple enough. But there’s a catch. This counts everything – files, symlinks, hidden items, the lot. If you only want directories, you need to be a bit more selective. ...

14 July 2020 · 1 min · 188 words · Shafiq Alibhai

Count files in a directory with a one-liner

Another quick command line question: how do you count just the files in a directory, excluding subdirectories and other stuff? The classic answer: ls -l . | egrep -c '^-' This lists everything in long format (ls -l), then counts lines that start with a hyphen – which is how ls marks regular files. Directories show up as d, symlinks as l, and so on, so the regex filters them out. It works, but it’s a bit of a trick and relies on understanding ls output format. A more straightforward approach uses find: ...

14 July 2020 · 2 min · 213 words · Shafiq Alibhai