Skip to content

Instantly share code, notes, and snippets.

Avatar

Zulhilmi Zainudin zulhfreelancer

View GitHub Profile
@zulhfreelancer
zulhfreelancer / view-yaml-gz-k8s-secret.md
Created January 12, 2023 03:02
How to view the content of *.yaml.gz file stored in Kubernetes secret?
View view-yaml-gz-k8s-secret.md

How to view the content of *.yaml.gz file stored in Kubernetes secret?

$ kubectl -n <NAMESPACE> get secret <SECRET> -o json | jq -r '.data."prometheus.yaml.gz"' | base64 -d | gunzip
@zulhfreelancer
zulhfreelancer / how-to-check-free-ram-linux.md
Created November 23, 2022 03:14
How to check free RAM/memory on Linux system?
View how-to-check-free-ram-linux.md
@zulhfreelancer
zulhfreelancer / delete-heroku-apps.sh
Last active November 8, 2022 01:51
How to bulk delete or leave all Heroku apps using bash script, Heroku CLI and jq?
View delete-heroku-apps.sh
# List all apps
heroku apps
# Delete all apps created by yourself
for app in $(heroku apps --json | jq -r '.[] | select(.owner.email == "<insert-heroku-email-here>") | .name'); do echo $app | heroku apps:destroy $app; done
# Leave all apps created by others where you were a collaborator
for app in $(heroku apps --json | jq -r '.[] | select(.owner.email != "<insert-heroku-email-here>") | .name'); do heroku apps:leave -a $app; done
# List all apps again
@zulhfreelancer
zulhfreelancer / dummy-exporter-deployment.yaml
Created October 31, 2022 08:11
Dummy / fake Prometheus exporter for Kubernetes testing
View dummy-exporter-deployment.yaml
apiVersion: v1
kind: Namespace
metadata:
name: dummy-exporter
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: dummy-exporter
@zulhfreelancer
zulhfreelancer / list-yaml-root-keys.md
Last active September 5, 2022 01:39
How to list all root keys in YAML file?
View list-yaml-root-keys.md

Problem

How to list all root keys in YAML file using yq v4 CLI?

Solution

yq4 is my terminal alias for yq above

Let's print all the root keys if they have enabled sub-key e.g.

@zulhfreelancer
zulhfreelancer / delete-all-evicted-pods.sh
Last active July 19, 2022 08:35
How to delete all evicted pods from all namespaces?
View delete-all-evicted-pods.sh
#!/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
Created March 22, 2022 03:46
How to view a specific/current context kubeconfig?
View current-context-kubeconfig.md

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

$ kubectl config view --minify --flatten

OR

$ kubectl config view --minify --raw
@zulhfreelancer
zulhfreelancer / install-tailscale-raspberry-pi.sh
Created March 4, 2022 04:12
How to install Tailscale Mesh VPN on Raspberry Pi
View install-tailscale-raspberry-pi.sh
#!/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 / rpi-benchmark.sh
Created February 25, 2022 13:35
Basic Raspberry Pi Benchmarking Script
View rpi-benchmark.sh
#!/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?
View helm-v3-uninstall-all-releases.sh
# 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