Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
!In the mood

Mateus Caruccio caruccio

💭
!In the mood
View GitHub Profile
@caruccio
caruccio / migrate-pv-to-zone.sh
Last active May 21, 2021
Migrate EBS Volume based PVs across AWS availability zones
View migrate-pv-to-zone.sh
#!/bin/bash
set -eu
NAMESPACE=$1
PVCNAME=$2
TARGETZONE=$3
DEPLOYMENTOBJ=$4
PVNAME=$(oc -n $NAMESPACE get pvc $PVCNAME --template={{.spec.volumeName}})
VOLUMEID=$(oc -n $NAMESPACE get pv $PVNAME --template={{.spec.awsElasticBlockStore.volumeID}} | cut -d/ -f 4)
@caruccio
caruccio / remove-stale-containers.py
Created Mar 25, 2018
Remove stale dockershim containers
View remove-stale-containers.py
#!/usr/bin/env python
## If you see messages like this on your kubelet journal:
##
## Mar 25 22:36:44 ip-10-0-3-67.ec2.internal dockerd-current[28612]: time="2018-03-25T22:36:44.419126265Z" level=error msg="Handler for GET /v1.24/containers/60532fa8184bdf41e52788194faa1253f1168e3ad4f54f7c159192fe66c4bb1d/json returned error: No such container: 60532fa8184bdf41e52788194faa1253f1168e3ad4f54f7c159192fe66c4bb1d"
##
## use this script to remove dockershim container files from /var/lib/dockershim/sandbox
import os, glob, subprocess
@caruccio
caruccio / bash-path-vars
Last active Nov 16, 2020
Path manipulation with bash vars
View bash-path-vars
$ FILE=/some/path/to/file.txt
###################################
### Remove matching suffix pattern
###################################
$ echo ${FILE%.*} # remove ext
/some/path/to/file
$ FILE=/some/path/to/file.txt.jpg.gpg # note various file exts
@caruccio
caruccio / Kubernetes-Stuck-Resources.md
Last active Oct 14, 2020
How to identify and remove resources stuck in Terminating state
View Kubernetes-Stuck-Resources.md

Namespaces

List all resources within a namespace

NS=some-namespace

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $NS
@caruccio
caruccio / kubectlgen
Created Jan 3, 2020
Kubectl Generator - on-the-fly kubectl shortcuts
View kubectlgen
#!/usr/bin/python
from __future__ import print_function
import sys
def usage(argv):
print('Usage: %s [commands][resources][options][parameters]' % argv[0], file=sys.stderr)
print('\nCommands:', file=sys.stderr)
for s, l in commands:
print(' %s (%s)' % (s, l), file=sys.stderr)
@caruccio
caruccio / attr-tree.md
Last active Oct 16, 2019
Attribute tree
View attr-tree.md

Attribute tree

Based upon One-line Tree in Python, here is a tree-like class where struct is accesible by attributes rather than keys (much more readable IMHO):

from collections import defaultdict

class Tree(defaultdict):
	def __init__(self, *va, **kva):
		super(Tree, self).__init__(*va, **kva)
@caruccio
caruccio / pvc-copy.sh
Created Oct 4, 2019
Generates an rsync pod to copy between two PVCs
View pvc-copy.sh
#!/bin/bash
if [ $# -lt 3 ]; then
echo "Usage: $0 pod-name-suffix source-pvc-name destination-pvc-name [rsync options...]"
exit 1
fi
POD_SUFFIX=${1}
PVC_FROM=${2}
PVC_TO=${3}
@caruccio
caruccio / PS1.sh
Last active Aug 26, 2019
My bash PS1
View PS1.sh
# Based on code from http://andrewray.me/bash-prompt-builder/index.html
DELTA_CHAR="δ"
CONFLICT_CHAR=""
NOBRANCH_TEXT="no-branch"
REBASE_TEXT="✂ ʀebase"
# Colors for prompt
COLOR_RED=$(tput sgr0 && tput setaf 1)
COLOR_GREEN=$(tput sgr0 && tput setaf 2)
@caruccio
caruccio / bash-reload.sh
Last active Jun 25, 2019
Reload shell config in-place
View bash-reload.sh
## Ever had to add something to your shell's config files (i.e. .bashrc)
## and open a new shell? Well, that may be fine, but you can achieve the
## same result, plus without having to open a new window/tab
## or execute a child process.
##
## Idea taken from https://learn.hashicorp.com/vault/getting-started/install
## lets check if any command `hello` exists
$ hello
bash: hello: command not found
@caruccio
caruccio / kubectl.md
Created May 7, 2019 — forked from so0k/kubectl.md
Playing with kubectl output
View kubectl.md

Kubectl output options

Let's look at some basic kubectl output options.

Our intention is to list nodes (with their AWS InstanceId) and Pods (sorted by node).

We can start with:

kubectl get no