Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
!In the mood

Mateus Caruccio caruccio

💭
!In the mood
View GitHub Profile
@caruccio
caruccio / Kubernetes-Stuck-Resources.md
Last active Jul 28, 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 / 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 / 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
@caruccio
caruccio / getopts.md
Created Apr 9, 2019
Read shell options with positional arguments
View getopts.md

This example shows how to read options and positional arguments from a bash script (same principle can be applied for other shells).

# some global var we want to overwrite with options
force=false
help=false
log=info
ARGS=() ### this array holds any positional arguments, i.e., arguments not started with dash

while [ $# -gt 0 ]; do
@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 / spread.sh
Last active Sep 26, 2018
Spread parameters
View spread.sh
$ function spread_parameter {
local p="$1"
shift
local IFS=","
eval "echo $(echo "$p\ {$*}")"
}
$ spread_parameter --include '*.jpg' '*.gif' '*.svg'
--include *.jpg --include *.gif --include *.svg
@caruccio
caruccio / on.sh
Created Aug 24, 2018
kubectl namespace switcher
View on.sh
# Switch kubernetes namespaces withou touching ~/.kube/config
# Example:
#
# $ on kube-system
# NAME STATUS AGE
# kube-system Active 1y
# $ k get pod
#
on()
@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 / migrate-pv-to-zone.sh
Last active May 14, 2020
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)
You can’t perform that action at this time.