Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
thbkrkr / eckurl
Last active January 23, 2024 09:26
curl Elasticsearch clusters managed by ECK - eckurl ns1/es1 /_cat/health
#!/bin/bash -eu
get-password() {
kubectl -n $ns get secret $esName-es-elastic-user -o go-template='{{.data.elastic | base64decode}}'
}
port-forward-es() {
if [[ "${V:-}" == "1" ]]; then
echo kubectl -n $ns port-forward "service/$esName-es-http" 9200
fi
@thbkrkr
thbkrkr / gcloud-ssh-sysctl-vmmaxmapcount.sh
Created November 7, 2019 19:42
Set vm.max_map_count=262144 on the nodes of a GKE cluster #k8s
#!/bin/bash -eu
# Increase Virtual Memory for Elasticsearch on GKE
# https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
# Dependencies: kubectl, gcloud, jq
nodes() {
kubectl get nodes -o custom-columns=n:.metadata.name --no-headers
}
@thbkrkr
thbkrkr / es-eck-gke-quickstart.sh
Last active November 18, 2023 01:17
Elasticsearch on GKE using ECK
#!/bin/bash -eu
# install kubectl: https://kubernetes.io/docs/tasks/tools
# install gcloud: https://cloud.google.com/sdk/docs/install
# authenticate: gcloud auth login
# gcloud container clusters create c0 --region europe-west1
kubectl create -f https://download.elastic.co/downloads/eck/2.10.0/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/2.10.0/operator.yaml
@thbkrkr
thbkrkr / gen-ssl.sh
Created April 7, 2015 16:15
Generate Self-Signed SSL Certificate without prompt
# Generate a passphrase
openssl rand -base64 48 > passphrase.txt
# Generate a Private Key
openssl genrsa -aes128 -passout file:passphrase.txt -out server.key 2048
# Generate a CSR (Certificate Signing Request)
openssl req -new -passin file:passphrase.txt -key server.key -out server.csr \
-subj "/C=FR/O=krkr/OU=Domain Control Validated/CN=*.krkr.io"
@thbkrkr
thbkrkr / list.rb
Last active July 25, 2023 07:54
Kafka JMX MBeans list
com.sun.management:type=DiagnosticCommand
com.sun.management:type=HotSpotDiagnostic
java.lang:name=CodeCacheManager,type=MemoryManager
java.lang:name=Code Cache,type=MemoryPool
java.lang:name=Compressed Class Space,type=MemoryPool
java.lang:name=G1 Eden Space,type=MemoryPool
java.lang:name=G1 Old Generation,type=GarbageCollector
java.lang:name=G1 Old Gen,type=MemoryPool
java.lang:name=G1 Survivor Space,type=MemoryPool
java.lang:name=G1 Young Generation,type=GarbageCollector
@thbkrkr
thbkrkr / docker-creds-secret.sh
Created July 7, 2023 12:06
Create a Kubernetes Secret with Docker registry creds stored in docker-credential-desktop
#!/bin/bash -eu
to_auth() {
jq -r '.Username,.Secret' | paste -sd ":" - | tr -d '\n' | base64
}
main() {
registry="$1"
jq -cnM --arg auth $(docker-credential-desktop <<< "$registry" | to_auth) '{
"auths": { "'"$registry"'": { "auth": $auth } }
@thbkrkr
thbkrkr / release-helm.sh
Created April 28, 2023 09:25
Release Helm charts
#!/usr/bin/env bash
#
# Script to release Helm charts.
#
# Requires: helm, gsutil, yq.
#
# Usage: release.sh CHART_DIR
#
@thbkrkr
thbkrkr / get.sh
Created April 14, 2023 21:20
Configure an Elasticsearch Snapshot Repository with a StackConfigPolicy - #ECK
> k get es,scp
NAME HEALTH NODES VERSION PHASE AGE
elasticsearch/xyz green 1 8.7.0 Ready 6m
NAME READY PHASE AGE
stackconfigpolicy/snapshot-repo 1/1 Ready 5m
> eckurl default xyz /_snapshot
{"repo-snapshots":{"type":"s3","settings":{"readonly":"true","base_path":"snapshots/default-xyz"}}}
@thbkrkr
thbkrkr / disable-jenkins-jobs-if-too-much-failures.groovy
Created March 5, 2014 15:59
Groovy script to disable Jenkins Jobs which name contains "ping" or "post" if the last x result builds are failures
def ret = 0
def MAX_FAILURES = 3
def projects = jenkins.model.Jenkins.instance.projects.findAll { it.name.contains("ping") || it.name.contains("post") }
for (p in projects) {
def projectName = p.name
@thbkrkr
thbkrkr / Default (Linux).sublime-keymap
Last active August 31, 2022 03:54
Custom & Eclipse shortcuts key bindings (keyboard mapping) for Sublime Text 2 and 3
[
{ "keys": ["f12"], "command": "htmlprettify"},
{ "keys": ["f1"], "command": "fold" },
{ "keys": ["f2"], "command": "unfold" },
{ "keys": ["ctrl+à"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
{ "keys": ["ctrl+!"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["ctrl+space"], "command": "auto_complete" },
{ "keys": ["ctrl+space"], "command": "replace_completion_with_auto_complete", "context":
[
{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },