Kubernetes Cheatsheet
The get parameter is a powerful way of discovering your kubenetes resources. You can use it to query:
- namespace
- pod
- node
- deployment
- service
- replicasets
$ kubectl get nodes$ kubectl get ns # ns is an abreviation for namespace$ kubectl get pods -n kube-system
The create command can do just that for:
- service
- cronjob
- deployment
- job
- namespace (or ns)
$ kubectl create ns hello-world$ kubectl create cronjob my-cronjob --image=alpine --schedule="*/15 * * * *" -- echo "hi there"
Extract a Single File from a Tarball
Suppose I have a tarball (.tar.gz file) which is large and I only want to extract a specific file from it. If I know the name of the file all I have to do is pass the file’s relative path that it is stored under to the command line.
Here is an example of the error you will get if you pass the incorrect file specification:
$ tar zxvf dirtree-tarball.tar.gz file-7-30003.txt
tar: file-7-30003.txt: Not found in archive
Since I don’t have the full path, I can just search for it:
Updating My Home Lab using Ansible
I have a variety of Raspberry Pis that I use for various tasks like my Tiny-Tiny RSS server, Gitea server, and Calibre server among other things. In order to keep them updated I use Ansible.
My update script is fairly simple:
$ cat update-pis.sh
#!/bin/bash
ansible-playbook ./playbooks/apt.yml --user memyselfandi \
--ask-pass --ask-become-pass -i ./inventory/hosts $@
The YAML playbook is likewise very simple:
$ cat ./playbooks/apt.yml
- hosts: "*"
become: yes
tasks:
- name: Update System Package Cache (apt)
apt:
update_cache: yes
upgrade: 'yes'
- name: Upgrade System Packages (apt)
apt: upgrade=full
- name: Remove unused dependencies
apt: autoremove=true
- name: Check if reboot is required
shell: "[ -f /var/run/reboot-required ]"
failed_when: False
register: reboot_required
changed_when: reboot_required.rc == 0
notify: reboot
handlers:
- name: reboot
command: /sbin/reboot
Although I can run this in a cronjob, I tend to run it manually (for now). I’m thinking about doing some major revisions to my Pi configuration anyway. Stay tuned for more on that subject.
List All MACs on the Local Network
Per the manpage:
The
arptool manipulates or displays the kernel’s IPv4 network neighbor cache. It can add entries to the table, delete one or display the current content. ARP stands for Address Resolution Protocol, which is used to find the media access control address of a network neighbor for a given IPv4 Address.
You can use the arp command to list all of the devices on the local network. It is often useful to find the identities of hidden devices on your network. For example, if you just plugged a Raspberry Pi into your local network and need to find its IP address in order to connect to it via SSH.
KVM: Configure libvirt Network
You can update the network configuration for your KVM installation using the command line using the virsh command.
To list all of the available network enter the following command. The --all will is used to include the inactive networks:
# virsh net-list --allName State Autostart-----------------------------------------default active yesNattedNetwork active yes
Install sbopkg on Slackware
Sbopkg is a command‐line and dialog‐based tool to interact with the SlackBuilds.org repository, a collection of third‐party SlackBuild scripts to build Slackware packages.
Here are the steps for installing the latest version of sbopkg with Slackware.
-
Download the latest Slackware package from
https://www.sbopkg.org/downloads.phpusing whatever method you find most convenient. At the time of this writing the latest version ishttps://github.com/sbopkg/sbopkg/releases/download/0.38.2/sbopkg-0.38.2-noarch-1_wsr.tgz. I will use that version in the commands below. If the version has changed, you would use the new filename in the commands. You can also usewget <packagename>to download it directly.
Copying a Directory Tree Recursively Using tar
You can use tar to copy a directory tree to another directory in one shot along with preserving ownership, permissions and timestamps. This also avoids making an intermediary tarfile which may cause problems if the size of the file copy is large and the storage resources are low. Just cd to the top of the directory that you want to copy and begin.
Let’s assume that you want to copy the contents of the source directory to a target directory:
Removing Blank Spaces from a Group of File Names
This set of commands iterate over each file in the current directory and will replace any blank spaces in a filename with an underscore (_).
First, we’ll create a set of sample files:
$ for i in {0..9}; do touch "file-${i} (number-${i}).txt"; done$ lsfile-0\ (number-0).txt file-4\ (number-4).txt file-8\ (number-8).txtfile-1\ (number-1).txt file-5\ (number-5).txt file-9\ (number-9).txtfile-2\ (number-2).txt file-6\ (number-6).txtfile-3\ (number-3).txt file-7\ (number-7).txt
Remove Parentheses from File Names
This script will rename Windows backup files by removing the ’ (date)’ from the filename. It will remove the parentheses and everything between them from the file name, so that a file with the name file-1 (2023-09-10).txt will be renamed to file-1.txt. Note that since the data between the parentheses will be removed, the resulting file name must be unique for this script to prevent data from being overwritten. Other than that it should work for any fileset that meets the beforementioned constraints.
Swapping the CMD and Control Keys on a Macbook Running Linux
I find it annoying not having a CTRL key available for both hands so I tend to swap the Command and CTRL key settings on my 2012 “Slackbook”.
- Launch a terminal
- Edit the X11 Keyboard Extension
# vim /usr/share/X11/xkb/symbols/pc
- Make the following changes. Ensure your file looks like this:
key <LCTL> { [ Super_L ] };key <LWIN> { [ Control_L ] };...key <RCTL> { [ Super_R ] };key <RWIN> { [ Control_R ] };