Skip to content

Instantly share code, notes, and snippets.

@dchaumond
dchaumond / gist:9e05d50afff5945d285e0b6b6f7cf654
Created June 3, 2020 13:17
Bash, check empty string (too many time search from the net ...)
[[ ! -z "$var" ]] && echo "Not empty" || echo "Empty"
@dchaumond
dchaumond / gist:bbebc4371fee8a458d7e3b5edfbf3679
Created March 31, 2020 09:22
Unlock namespaces stucked in Terminating mode, remove finalizers
#!/usr/bin/env bash
namespace=$1
kubectl get ns $namespace -o json | jq '.spec = {"finalizers":[]}' | kubectl replace --raw /api/v1/namespaces/$namespace/finalize -f -
@dchaumond
dchaumond / gist:0d4920b7109613bcddc88fb23761fff1
Created December 5, 2019 14:49
kube, describe all nodes
kubectl describe nodes -l node-role.kubernetes.io/node
@dchaumond
dchaumond / gist:ca5cb4af03166a952d91406c40c3d983
Created August 1, 2019 07:30
Extract k8s resource names to apply later another command
names=$(kubectl get pods -l <label> -n <namespace> -o jsonpath={.items..metadata.name})
for pod_name in $names; do ... $pod_name ... done
@dchaumond
dchaumond / gist:70b0ce8d2ca07da198e4e08a55423dd4
Created August 1, 2019 07:28
Force delete statefulset pods
kubectl delete pods <pod> --grace-period=0 --force
@dchaumond
dchaumond / gist:5cf9cadd4e10a5cd693f6111ecde82ba
Created August 1, 2019 07:23
k8s API inside a container
apk update && apk add curl jq;
K8S=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT;
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) && CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt;
api() {
curl -s -H "Authorization: Bearer $TOKEN" --cacert $CACERT $K8S/api/v1/$1
}

Keybase proof

I hereby claim:

  • I am dchaumond on github.
  • I am dchaumond (https://keybase.io/dchaumond) on keybase.
  • I have a public key ASDAyXEafPFZIvjV88A7-_YdNKrrbWmB3es5RhpIHy9HKgo

To claim this, I am signing this object: