What Is The Watch Mechanism in Kubernetes?

Question
What is the "watch mechanism" in Kubernetes?

Solution
A notification system from the API server to trigger changes in Kubernetes. In Kubernetes there are observable events. The watch mechanism is a system for listening for specific events to respond to. The Kubelet, the Scheduler, the kube-dns pod, and individual controllers are components that use the watch mechanism. The API server is a central component that watching components are aware of. (This was summarized from pages 319, 321, and 323 of Kubernetes in Action.)

If you want to see how the relevant --watch flag works, run this command:

kubectl get pods --watch

(This command was taken from 318 of Kubernetes in Action.)

To see various watch.go files, see this: https://github.com/kubernetes/kubernetes/search?q=filename%3Awatch.go

To see the source code of watch.go you for etcd you used to be able to go to this file: https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go

How Do You Troubleshoot the pipenv error message “tomlkit.exception”?

Problem scenario
You try to run a pipenv command, but you get an error about "tomlkit.exception".

Solution
Copy the Pipfile to a new name (to back it up). Delete the original Pipfile. Try to run the command again. If it still fails, try removing pipenv by uninstalling it. Then reinstall pipenv. Then reboot the computer.

How Do You Install and Configure Apache Camel on a Linux Server?

Problem scenario
You want to install and configure Apache Camel from source on any distribution of Linux. What do you do?

Solution
You cannot. But there is a way to use Apache Camel as a test.

Background: It is not something that is can be purely installed-and-configured like other applications. Camel is a framework for integrating messaging solutions or microservice architecture. Camel can be used as a library within Spring Boot and other tools (according to https://camel.apache.org/). You can use Camel with Maven (or other tools). The following is how to use Camel with Maven as a proof-of-concept.

Prerequisites if you want to use the script below:
Your server has 4 GB of memory. If this memory is mostly from swap space, the installation will take several hours to complete. With two CPUs and 4 GB of RAM, it will take 40 to 60 minutes to complete. You have Java and Maven installed. If you need assisting installing Java, see this posting. If you need assisting installing Maven, see this posting.

Procedures
Run this script. (It was tested to work with SUSE Linux Enterprise Server 15 SP2, Ubuntu 20.04.1 LTS, and RHEL 8.3.)

# Written by www.continualintegration.com.
# We incorporated a command found here: https://stackoverflow.com/questions/11616835
# Last modified on 11/26/20.

camelversion=3.6.0

echo "Warning: This script will wipe out previous installations of Mavan and Java to create new ones.  It will also create a 4 GB swap space file on the hard drive."
sleep 5
echo "Installing the dependencies of Camel at this time..."
curl https://www.continualintegration.com/wp-content/uploads/2020/11/swapspace4G.txt > /tmp/swapspace4G.sh
curl https://www.continualintegration.com/wp-content/uploads/2020/11/javainstallscript.txt > /tmp/javainstallscript.sh
curl https://www.continualintegration.com/wp-content/uploads/2020/11/mavenscript.txt > /tmp/mavenscript.sh
sed -i 's/\r$//' /tmp/swapspace4G.sh
sed -i 's/\r$//' /tmp/javainstallscript.sh
sed -i 's/\r$//' /tmp/mavenscript.sh
bash /tmp/swapspace4G.sh
bash /tmp/javainstallscript.sh
bash /tmp/mavenscript.sh
echo "Installation of the dependencies should be complete now."
echo "********************************************************"
echo "Beginning the installation of Apache Camel.  This process on a server with 4 GB of RAM takes 30 to 60 minutes.  If it has 1 GB of RAM [and uses swap space], it may take several hours."

curl -Ls https://mirrors.sonic.net/apache/camel/apache-camel/$camelversion/apache-camel-$camelversion-src.zip > /tmp/apache-camel-$camelversion-src.zip
echo "Verify unzip is installed..."
apt -y install unzip
yum -y install unzip
zypper -n install unzip
echo "Two of the above commands should have failed.  Do not be alarmed if there were previous failures with 'commmand not found' messages"
cd /opt
cp /tmp/apache-camel-$camelversion-src.zip .
unzip apache-camel-$camelversion-src.zip 
echo "Now attempting to set the permissions of the new directory and its subdirectories"
gn=$(groups | awk '{print $1}')
un=$whoami
chown -R $un:$gn apache-camel-$camelversion
cd apache-camel-$camelversion
echo "This process may take hours to complete"
MAVEN_OPTS=-Xmx5120m
export MAVEN_OPTS=-Xmx5120m
mvn clean install -Pfastinstall
#mvn clean install -X
# The above stanza is commented out as a suggestion of something you could potentially run.

How Do You Troubleshoot an Error about sqlite3 Not Being Installed when It Is Actually Installed?

Problem scenario
You have installed sqlite3. It is a version above 3.22.0. But when you run "make deps" you see this error message:

checking for SQLITE… no
configure: error: Package requirements (sqlite3 >= 3.22.0) were not met:
No package 'sqlite3' found

What should you do?

Solution
Run this:
sudo apt -y install libsqlite3-dev

How Do You Get the NameNode Process to Start in Hadoop?

Problem scenario
You have run start-dfs.sh and start-yarn.sh. You have stopped all the Hadoop services too. When you run "jps", the NameNode is not showing up. You have tried a variety of different troubleshooting methods (including rebooting the NameNode). The NameNode has never worked correctly. You can delete all the data in the cluster because it never really worked. What should you do?

Solution
Run this but remember it will delete all your data:

hdfs namenode -format # Warning: this command will delete all your data in Hadoop

How Do You Troubleshoot the fdisk Error “cannot open /dev/sdaX: No such file or directory”?

Problem scenario
You have added a partition to Linux. When you type "df -h" you do not see evidence that it is available. You tried the "sudo lsblk" command, but you do not see the device. The "fdisk -l" command does show the new device and the size that is available. The command ll /dev/sd* does not show your new device.

When you run "fdisk /dev/sdaX", you get this: "fdisk: cannot open /dev/sdaX: No such file or directory"

How do you make it available?

Solution
Reboot the server.

How Do You Use an Array in Linux (Bash)?

Problem scenario
You are aware that arrays are a supported data type in Bash. You would like to iterate through some variables as arrays could enable complex logic. What do you do?

Solution
The array is zero-based. So the first element is referred to by index number 0.

continualarray=(dog cat hamster rabbit horse cow)
echo ${continualarray[2]}
echo ${continualarray[5]}

Create a file foobar.txt to test an array's line-reading capacity.

$ cat /tmp/foobar.txt
this is a sentence
another sentence is here.
some more text.
various words; another phrase.

Here is an example of the built-in readarray command:

readarray rows < /tmp/foobar.txt
echo ${rows[2]) # this will print out this:
some more text.

How Do You Create a Windows 2016 Server with Vagrant and Oracle VirtualBox?

Problem scenario
You want to use Windows 2016 with 2 GB of RAM. You have Oracle VirtualBox installed on a Linux server. You want the VM to be able to communicate with the host or other VMs on the host. You have a license for Windows 2016. What should you do?

Solution
Prerequisite: You have Oracle VirtualBox set up. You know what adapters you can attach a VM to. (Options may include enp1s0, virbr0, virbr0-nic or others.)

  1. Install Vagrant.
  2. Run this command:
    gem list | grep libvirt
  3. Verify that libvirt's version is at least 0.6 or higher. If it is, go to step #2. If it is lower than that, use the following two commands (uncommented out):
# gem uninstall fog-libvirt
# gem install fog-libvirt

4. Run these two commands:

vagrant plugin install winrm
vagrant plugin install winrm-elevated

5. Use this as the Vagrantfile (but not for commercial purposes unless you have a license):

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "mwrock/Windows2016"
  config.vm.provider "virtualbox"
  config.vm.network :public_network, :bridge => "enp1s0", adapter: "1"
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
   config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
     vb.memory = "2048"
   end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
  1. Run this command: vagrant up
    Do not be alarmed if it hangs at the "default WinRM transport: negotiate" step.

You may see this (because there is only one adapter and it is a bridged adapter):

default: WinRM address: 127.0.0.1:55985
default: WinRM username: vagrant
default: WinRM execution_time_limit: PT2H
default: WinRM transport: negotiate
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

How Do You Filter the Output of an AWS CLI Command?

Problem scenario
You want to return only the JSON of the output that is related to a specific role -- not the entire list of an "aws iam list-roles" command. What do you do?

Solution
Prerequisite
You must have the AWS CLI installed. If you need assistance, see this posting.

Procedures
Use the "--query" flag. Often the syntax to structure a query in the results is the word to the right of the "list-" in an AWS CLI command. Such is the case for "aws iam list-roles":

Here is an example (just replace the "123456:role/foobar" with the Arn value right of the "arn:aws:iam" string):

aws iam list-roles --query 'Roles[?Arn==arn:aws:iam::123456:role/foobar]'

aws ec2 describe-subnets --query 'Subnets[?SubnetId==subnet-0a1234efgh]'

How Do You Write a Java Program to Accept a Character as Input and Do Something with It?

Problem scenario
You want to accept user input with a Java program. How do you write such a program?

Solution
Here is the program:

import java.util.Scanner;

public class acceptChar {

public static void main(String[] args) {
   System.out.println("Please enter a character, then press enter: ");
   Scanner in = new Scanner(System.in);
   char letter = in.next().charAt(0);
   System.out.println(letter);
  }
 }