Skip to content

Instantly share code, notes, and snippets.

View tuxfight3r's full-sized avatar
Working from home

Mohan Balasundaram tuxfight3r

Working from home
View GitHub Profile
tuxfight3r /
Last active November 17, 2023 15:37
consume message from kafka topic from any given offset

Consume kafka messages from a specific offset

There are 2 ways of consuming kafka messages from a given topic at a specific offset.

Consume the messages from any offset by creating consumer group

  # describe a given group and sort by partition
/home/tools/confluent/bin/kafka-consumer-groups --bootstrap-server ${KAFKA_BROKER} --command-config ${CONFIG} --timeout 15000 --group $1 --describe | sort -k2,3
tuxfight3r / gist:169867c001684411814e5f8456f4a6ed
Created July 4, 2023 09:50
Java JMX inspection via visualvm or jconsole for a pod inside kubernetes
#to be able to view the java jmx internals of an application running in kubernetes as a pod
# set the below environment value in the pod definition
tuxfight3r /
Created February 8, 2023 16:59
bash calculate time elapsed between two date timestamps
date1="2023-02-08 10:50:33"
date2="2023-02-08 14:10:33"
date1_seconds=$(date -d "$date1" +"%s")
date2_seconds=$(date -d "$date2" +"%s")
duration=$(( $date2_seconds - $date1_seconds ))
echo "Time Elapsed: $(($duration/3600)) hours $(($duration %3600 / 60)) minutes and $(($duration % 60)) seconds."
tuxfight3r /
Last active February 8, 2023 16:56
bash format number with thousand separator for busybox shell
For environments where there is no full fledged printf. The below function does a pretty print of numbers with thousand separator


#converts given number to pretty format
function pretty_num(){
     awk '{ len=length($0); res=""; for (i=0;i<=len;i++) { res=substr($0,len-i+1,1) res; if (i > 0 && i < len && i % 3 == 0) { res = "," res } }; print res }'|sed -e's/-,\(.*\)/-\1/g'


tuxfight3r /
Last active January 6, 2023 10:14
kubectl jump server via kubectl port-forward
#!/usr/bin/env bash
# Allows you to connect to remote endpoints via port forward
set -e
function cleanup {
tuxfight3r /
Last active December 4, 2023 22:10
KafkaCat configuration for AWS MSK

KafkaCat Configuration for AWS MSK

Set the below environment variable with the following values

NOTE: Kafkacat is renamed to kcat recently and the config variable should be KCAT_CONFIG for version 1.7 onwards.

# you can export the variable or present the config with -F parameter for kafkacat
export KAFKACAT_CONFIG=/home/tools/persistent/kcat/kafkacat_config

Contents of kafkacat configuration

#Simple script to test all the pods liveness/readiness
#creates portforward and curls the endpoint for status
#clears the portforward at the end of the script
#uses bash v3 based implementation.
#Test only the pods which are up.
tuxfight3r / gist:b67e94e5a09c61c0c31b00ec0a6e8eb5
Created July 14, 2021 17:19
python decode kubernetes service token (JWT Token)
# retrieve the default kubernetes service account token
kubectl get secret $(kubectl get serviceaccounts default -o jsonpath='{.secrets[0].name}') -o json|jq -r .data.token |base64 -D
# Decode it using Python (pip install PyJWT)
import jwt
jwt.decode(var, options={"verify_signature":False})
tuxfight3r / selfsigned-clusterissuer.yml
Last active July 15, 2021 21:08
kube cert-manager cert issuer
kind: ClusterIssuer
name: selfsigned-cluster-issuer
selfSigned: {}
tuxfight3r /
Last active March 30, 2024 17:34
bash script to choose an option with dialog box
BACKTITLE="Cluster Options"
TITLE="Select Cluster"
MENU="Choose one of the following options:"