Skip to content

Instantly share code, notes, and snippets.

View zulhfreelancer's full-sized avatar

Zulhilmi Zainudin zulhfreelancer

View GitHub Profile
@zulhfreelancer
zulhfreelancer / delete-all-evicted-pods.sh
Last active April 13, 2023 06:05
How to delete all evicted pods from all namespaces?
#!/bin/bash
# This script is for Mac OSX users. If you are on Linux, replace 'gxargs' with 'xargs'.
# To install 'gxargs' command using Homebrew, run 'brew install findutils' first.
# Without parallel (ideal for small number of pods)
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | gxargs -n 1 -d '\n' bash -c 'kubectl delete pod $0 $1'
# With parallel (ideal for big number of pods)
# To install 'parallel' command using Homebrew, run 'brew install parallel' first.
@zulhfreelancer
zulhfreelancer / current-context-kubeconfig.md
Last active May 24, 2023 03:13
How to view/extract a specific/current context kubeconfig?

How to view/extract a specific/current context kubeconfig?

If you have multiple Kubernetes contexts (list them by kubectl config get-contexts) and you want to view or extract the kubeconfig just for current/selected context, you can use one of the following command:

$ kubectl config view --minify --flatten

OR

@zulhfreelancer
zulhfreelancer / install-tailscale-raspberry-pi.sh
Created March 4, 2022 04:12
How to install Tailscale Mesh VPN on Raspberry Pi
#!/bin/bash
# Step 1 - Install Tailscale
sudo apt-get install apt-transport-https && \
curl -fsSL https://pkgs.tailscale.com/stable/raspbian/buster.gpg | sudo apt-key add - && \
curl -fsSL https://pkgs.tailscale.com/stable/raspbian/buster.list | sudo tee /etc/apt/sources.list.d/tailscale.list && \
sudo apt-get update && \
sudo apt-get install -y tailscale && \
sudo tailscale up
@zulhfreelancer
zulhfreelancer / get-isp-name.sh
Created March 2, 2022 03:19
Bash one-liner script to get current ISP name
# Method #1
whois $(whois $(curl -s icanhazip.com) | grep origin | awk '{print $2}') | grep -i descr | cut -d: -f2- | tail -n1 | xargs
# Method #2
whois $(whois $(curl -s icanhazip.com) | grep origin | awk '{print $2}') | grep -i 'org-name\|orgname' | cut -d: -f2- | tail -n1 | xargs
# Method #3
whois $(curl -s icanhazip.com) | grep -i 'org-name\|orgname' | cut -d: -f2- | tail -n1 | xargs
@zulhfreelancer
zulhfreelancer / rpi-benchmark.sh
Created February 25, 2022 13:35
Basic Raspberry Pi Benchmarking Script
#!/bin/bash
vcgencmd measure_temp
vcgencmd get_throttled
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run >/dev/null 2>&1
vcgencmd measure_temp
vcgencmd get_throttled
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run >/dev/null 2>&1
vcgencmd measure_temp
vcgencmd get_throttled
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run >/dev/null 2>&1
@zulhfreelancer
zulhfreelancer / helm-v3-uninstall-all-releases.sh
Created January 27, 2022 04:12
[Helm v3] How to uninstall all releases from all namespaces?
# Require 'jq'
# https://stedolan.github.io/jq/
helm list -A -o json | jq -r '.[] | .name + " " + .namespace' | xargs -n2 sh -c 'helm uninstall $1 -n $2' sh
@zulhfreelancer
zulhfreelancer / open-a-port-in-oracle-cloud-instance.sh
Last active December 23, 2021 18:56
How to open a port in Oracle Cloud Instance?
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPORTANT
# Make sure you already create an ingress rule for the port that you want to open in Oracle Cloud virtual firewall aka
# "Security Lists". This tutorial might be useful for you:
# ---> https://youtu.be/1AIXULHjabQ
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# SSH into the instance
$ ssh <username>@<ip_address>
@zulhfreelancer
zulhfreelancer / git.md
Created November 22, 2021 09:09
Git: how to count number of uncommited files?

Git: how to count number of uncommited files?

$ git status -uall --porcelain | wc -l
@zulhfreelancer
zulhfreelancer / k8s-ephemeral.sh
Created October 8, 2021 04:44
Kubernetes ephemeral pod (like `docker run --rm`)
kubectl run debug --rm -i --tty --restart=Never --image=alpine --namespace=default -- /bin/sh
@zulhfreelancer
zulhfreelancer / ip-address-websites.md
Created August 6, 2021 06:51
List of websites that can return IP address