Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
@caruccio
caruccio / canivete.md
Created May 20, 2024 14:51
Talk - Canivete suiço de gambiarras
@caruccio
caruccio / kubectl-show_tls.md
Last active May 17, 2024 12:45
Show decoded tls cert and key from a secret

$ cat kubectl-show_tls

#!/bin/bash

BIN_AWK=${0}.awk

command kubectl get secret -o json "$@" \
  | jq 'select(.type="kubernetes.io/tls") | .data|.[]|values|@base64d' \
  | xargs printf "%b" \
@caruccio
caruccio / kubectl-show_secret
Last active May 17, 2024 12:27
Show decoded contents of a secret
#!/bin/bash
usage()
{
echo "Usage: kubectl show-secret [-n namespace] secret [...secret]"
exit
}
while [ $# -gt 0 ]; do
while getopts n: opt; do
@caruccio
caruccio / caddy-insecure-tls-reverse-proxy.md
Last active May 17, 2024 12:32
Caddy insecure tls reverse proxy

This example shows how to access an insecure tls server using a reverse proxy

$ cat insecure-proxy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: prom-proxy
@caruccio
caruccio / aws-assume-role
Created May 17, 2024 11:53
AWS Assume Role
#!/bin/bash
#
# Install:
# $ echo 'source ~/bin/aws-assume-role' >> ~/.bashrc
#
# Usage:
# $ aws-assume-role [name]
#
# Prerequisite:
# Create an IAM role like this in the account you what access:
@caruccio
caruccio / kubectl-color
Created May 12, 2024 18:47
Example kubectl plugin
#!/bin/bash
ContainerCreating=$(tput setaf 13) # magenta
Pending=$(tput setaf 3) # yellow
Running=$(tput setaf 2) # green
Error=$(tput setaf 1) # red
BackOf="$Error"
Terminating=$(tput setaf 8) # gray
Finished="$Terminating"
Completed="$Terminating"
@caruccio
caruccio / kubectl-top_node_pod
Created May 12, 2024 12:20
kubectl top pods in a node
#!/bin/bash
function usage()
{
echo Usage: $0 '[--cpu/-c|--memory/-m]' nodes...
echo Sort by memory is the default
exit ${1:-0}
}
node_names=()
@caruccio
caruccio / kubectl-count_objects
Last active May 12, 2024 12:21
Count all objects in a clusters
#!/bin/bash
kubectl api-resources --verbs=list -o name --namespaced=false | while read kind; do
echo -n "$kind: "
kubectl get --ignore-not-found -A $kind | wc -l
done 2>/dev/null
kubectl api-resources --verbs=list -o name --namespaced=true | while read kind; do
echo -n "$kind: "
kubectl get --ignore-not-found -A $kind | wc -l
@caruccio
caruccio / kubectl-evict
Created May 12, 2024 12:17
kube tl evitc <pods...>
#!/bin/bash
function usage()
{
echo Usage: $0 '[--namespace NS/-n NS] [--all/-a|POD...]'
exit $1
}
all_pods=false
pod_names=()
@caruccio
caruccio / kubectl-pfz
Last active May 12, 2024 12:18
Kubectl port-forward with fzf service selector
#!/bin/bash
##
## kubectl port-forward on selected services, combined by all service ports.
##
function kpfz()
{
local svc_ports_command="jq -r '.items[] |
{
name: .metadata.name,