Skip to content

Instantly share code, notes, and snippets.

View zulhfreelancer's full-sized avatar

Zulhilmi Zainudin zulhfreelancer

View GitHub Profile
@zulhfreelancer
zulhfreelancer / find-pod-by-uid.md
Last active October 3, 2024 02:29
How to find a pod by UID?

How to find a pod by UID?

Option #1

kubectl get pods -A -o json | jq -r '.items[] | select(.metadata.uid == "<UID>") | .metadata.name, .metadata.namespace'

Option #2

@zulhfreelancer
zulhfreelancer / run-psql-in-kubernetes.md
Created September 14, 2024 15:58
How to run a temporary psql container in Kubernetes for testing/debugging?

How to run a temporary psql container in Kubernetes for testing/debugging?

$ k run psql-client --rm -i --tty --image jbergknoff/postgresql-client --command /bin/sh
/ # which psql
/usr/bin/psql

/ # psql --version
psql (PostgreSQL) 12.3
@zulhfreelancer
zulhfreelancer / sort-htop-by-cpu-memory.md
Created September 10, 2024 06:34
How to sort `htop` by CPU or Memory?

How to sort htop by CPU or Memory?

Sort by CPU

htop -s PERCENT_CPU

Sort by Memory / RAM

@zulhfreelancer
zulhfreelancer / find-pods-image-pull-secrets.sh
Created August 19, 2024 04:00
Find pods that use specific image pull secret
# Replace the THE_SECRET_NAME
k get pods -A -o json | jq -r '.items[] | select(.spec.imagePullSecrets!=null) | select(.spec.imagePullSecrets[].name=="THE_SECRET_NAME") | {namespace: .metadata.namespace, name: .metadata.name}'
@zulhfreelancer
zulhfreelancer / list-clusterissuers.sh
Created August 15, 2024 07:09
List all DNS01 ClusterIssuers and provider names using `kubectl`
kubectl get clusterissuers -o json | jq -r '.items[] | select(.spec.acme != null) | select(.spec.acme.solvers[0] | keys[0]=="dns01") | {name: .metadata.name, provider: (.spec.acme.solvers[0].dns01 | keys[0])}'
@zulhfreelancer
zulhfreelancer / ipv4-brief-summary-linux.md
Created June 3, 2024 02:05
How to displays a brief summary of all IPv4 addresses assigned to the network interfaces Linux system?

How to displays a brief summary of all IPv4 addresses assigned to the network interfaces Linux system?

Command:

ip -4 -br a

Sample output:

@zulhfreelancer
zulhfreelancer / check-network-interface.md
Created June 3, 2024 01:55
How to check which network interface will be used to route/send packets for specific IP address?

How to check which network interface will be used to route/send packets for specific IP address?

# Install `ip` tool
apt update -y
apt install iproute2 -y

# Check
ip r get 8.8.8.8 fibmatch
@zulhfreelancer
zulhfreelancer / get-all-prometheus-metrics.md
Last active May 16, 2024 06:41
Get all Prometheus metrics and descriptions/help texts

Get all Prometheus metrics and descriptions/help texts

Requirement:

As JSON

curl -sg 'http://prom-server:prom-port/api/v1/metadata' | jq -r '.data'
@zulhfreelancer
zulhfreelancer / how-to-install-promtool.md
Created April 4, 2024 04:07
How to install promtool by Prometheus?

How to install promtool by Prometheus?

# Fetch latest version
TAG=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases | jq -r '.[] | .tag_name' | head -n 1)
echo $TAG

# Remove the `v` prefix
VERSION=$(echo $TAG | sed 's/v//')
echo $VERSION
@zulhfreelancer
zulhfreelancer / query-prometheus-from-cli.md
Last active April 4, 2024 04:13
How to query Prometheus from local CLI / Terminal

How to query Prometheus from local CLI / Terminal

Requirements

promtool - see installation steps here

Command

promtool query instant '' '' | jq