March 1, 2021

Running short-lived container to compile source code
$ sudo docker run --rm -it -v ${PWD}:/app -w /app openjdk:11-jdk-slim /bin/sh -c ./gradlew buildRun
Rsync over SSH on Spesific Port
$ rsync -avzhe 'ssh -p [port_number]' -P [user@remote_ip]:/path/to/file/source /path/to/file/destination
Scan IP on Network
$ nmap -sP [ip_address/prefix]
Search Available Version of Spesific Package on Debian Based OS
$ apt list -a <package_name>
Install Spesific Kubernetes Version
#example version 1.15.x#
$ sudo apt update;sudo apt install -qy kubelet=1.15.5-00 kubectl=1.15.5-00 kubeadm=1.15.5-00
Open Spesific Port on Centos 7
iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 9100 -j ACCEPT
Replace String Using Sed
sed -i 's/old-string/new-string/g'
Find and copy files
find /var/cache/dnf -iname "*.rpm" -exec cp {} packages/ \;
Encrypt secret envar value using Google KMS
echo -n "This is my secret" | gcloud kms encrypt --plaintext-file=- --ciphertext-file=- --location=global --keyring=mykeyring --key=myappkey | base64 -w 0
Encrypt file using Google KMS
gcloud kms encrypt \
    --key myappkey \
    --keyring mykeyring \
    --location global  \
    --plaintext-file \
Check DNS record
$ dig +noall +answer		204	IN	A		204	IN	A		204	IN	A		204	IN	A		204	IN	A		204	IN	A
Check service port
$ getent services 53

domain                53/tcp
Reset Docker Environment
docker container stop $(docker container ls -aq) && docker system prune -af --volumes
Troubleshoot SELinux Issue on RHEL/CentOS
1. Find your error from journalctl or audit.log then get the audit ID.
2. grep 1624284378.419:2066 /var/log/audit/audit.log |audit2why
Replace multiple file on OSX
find /to/my/path -type f -name "*.yaml" -exec sed -i '' -e 's/' {} \;
Generate Kubernetes secret and configmap YAML manifest
# Secret
kubectl create secret generic my-config --from-file=configuration/ -o yaml --dry-run

# Configmap
kubectl create configmap my-config --from-file=configuration/ -o yaml --dry-run