Created
June 15, 2025 08:47
-
-
Save dex4er/b63733cbf0e1188f15239b9e1c632ce9 to your computer and use it in GitHub Desktop.
kubectl addons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
_list=($(kubectl get --raw / |grep "^ \"/api"|sed 's/[",]//g')); | |
echo -e "GROUP\011RESOURCE" | |
for _api in ${_list[@]}; do | |
_aruyo=$(kubectl get --raw ${_api} | jq .resources); | |
if [ "x${_aruyo}" != "xnull" ]; then | |
kubectl get --raw ${_api} | jq -r ".resources[].name" | xargs -n1 echo ${_api} | tr ' ' '\011' | sort | |
fi; | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
node="$1" | |
if [[ ! $node ]]; then | |
echo "Usage: kubectl terminate NODE" 1>&2 | |
exit 1 | |
fi | |
context=$(kubectl config current-context) | |
region=$(echo $context | cut -d: -f4) | |
profile=$(echo $context | cut -d: -f5) | |
ip=$(kubectl get node $node -o custom-columns=IP:".metadata.annotations['alpha\.kubernetes\.io/provided-node-ip']" --no-headers) | |
if [[ -n $ip ]]; then | |
instance=$( | |
aws ec2 describe-instances \ | |
--profile "$profile" \ | |
--filters "Name=private-ip-address,Values=$ip" "Name=instance-state-name,Values=running" \ | |
--query "Reservations[].Instances[0].InstanceId" \ | |
--max-items 1 \ | |
--output text | | |
head -n1 | |
) | |
if [[ -n $instance ]]; then | |
aws ec2 terminate-instances --profile "$profile" --instance-ids "$instance" --output text | |
fi | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
namespace=$1 | |
if [[ -z $namespace ]]; then | |
echo "Usage: kubectl nsfinalize NAMESPACE" | |
exit 1 | |
fi | |
while read -r name status age; do | |
if [[ $name == $namespace ]] && [[ $status = Terminating ]]; then | |
kubectl get namespace "$namespace" -o json \ | |
| jq '.spec.finalizers=[]' \ | |
| kubectl replace --raw "/api/v1/namespaces/$namespace/finalize" -f - | |
exit 0 | |
fi | |
done < <(kubectl get ns --no-headers) | |
echo "No terminating namespace $namespace found" | |
exit 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
node="$1" | |
if [[ ! $node ]]; then | |
echo "Usage: kubectl ssm NODE" 1>&2 | |
exit 1 | |
fi | |
context=$(kubectl config current-context) | |
region=$(echo $context | cut -d: -f4) | |
profile=$(echo $context | cut -d: -f5) | |
ip=$(kubectl get node $node -o custom-columns=IP:".metadata.annotations['alpha\.kubernetes\.io/provided-node-ip']" --no-headers) | |
ssm "$ip" --profile "$profile" --region "$region" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment