Skip to content

Instantly share code, notes, and snippets.

View abdennour's full-sized avatar
🌴
On vacation

abdennour abdennour

🌴
On vacation
View GitHub Profile
@abdennour
abdennour / k8s_clean_exit_pods.sh
Created September 7, 2019 10:13
Clean Useless Pods
kubectl get po --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
kubectl get po --all-namespaces --field-selector 'status.phase==Evicted' -o json | kubectl delete -f -
kubectl get po --all-namespaces --field-selector 'status.phase==Pending' -o json | kubectl delete -f -
@abdennour
abdennour / kind_up.sh
Last active July 10, 2020 16:02
Run Cluster Command in one Command - kind
#!/bin/bash
kind_version=${1:-"v0.8.1"}
kind_bin_path=/usr/local/bin/kind
if [ ! -f ${kind_bin_path} ]; then
# curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${kind_version}/kind-$(uname)-amd64
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${kind_version}/kind-$(uname)-amd64"
chmod +x ./kind
sudo mv ./kind ${kind_bin_path}
@abdennour
abdennour / df_k8s_nodes.sh
Last active September 7, 2019 18:15
Check K8s Nodes Disk Space without SSH
cat <<EOF | kubectl apply -f -
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: disk-checker
labels:
tier: monitoring
app: disk-checker
version: v1
spec:
@abdennour
abdennour / k8s_node_maintenance_done.sh
Created September 7, 2019 18:18
Scripts for Maintaining Kubernetes Nodes
#!/bin/bash
node=${1};
k uncordon ${node}
@abdennour
abdennour / vault-policy-sample.sh
Last active September 13, 2019 10:26
Create ACL policy in Vault and Create User with that Policy
#!/bin/bash
# vault server -dev -dev-root-token-id="root"
policy_name=mypolicy
# export VAULT_ADDR='http://127.0.0.1:8200';
# pre-validation
vault secrets list
vault policy list
# add policy
@abdennour
abdennour / 00-infra.yaml
Last active May 9, 2025 13:47
Jenkins declarative Pipeline in Kubernetes with Parallel and Sequential steps
apiVersion: v1
kind: Pod
spec:
# dnsConfig:
# options:
# - name: ndots
# value: "1"
containers:
- name: dind
image: abdennour/docker:19-dind-bash
@abdennour
abdennour / README.md
Created September 15, 2019 14:27
Sketch Shortcut Cheat Sheet

alt text

@abdennour
abdennour / bitbucket_backup.sh
Created September 17, 2019 03:48
Backup All Git Repos with All branches
#!/bin/bash
team=${1};
repos_list_file=${2};
while read repo; do
if [[ ! -d "$repo" ]]; then
echo $repo clone...
git clone git@bitbucket.org:${team}/${repo}.git;
TIMEOUT=$((5 + RANDOM % 10));
@abdennour
abdennour / Dockerfile
Created October 4, 2019 04:48
Dynamically replace environment variable names by its values inside file
FROM perl:5-slim
WORKDIR /data
COPY myfile.txt .
RUN perl -pe 's/\$([_A-Z]+)/$ENV{$1}/g' < myfile.txt > /tmp/myfile.txt
RUN perl -pe 's/\$(\{)?([a-zA-Z_]\w*)(?(1)\})/$ENV{$2}/g' < /tmp/myfile.txt > myfile.txt
# Only substitute variable that are defined perl -pe 's{\$(\{)?(\w+)(?(1)\})}{$ENV{$2} // $&}ge'
@abdennour
abdennour / read-pipe-stdin
Created October 4, 2019 07:58
Bash script reads from pipe, stdin < or first argument
#!/bin/bash
# Available SYNTAX:
# --- $0 /path/file
# --- $0 < /path/file
# --- echo "my content" | $0
# either comes from first argument or from /dev/stdin.
content_to_replace="${1:-/dev/stdin}"