Quick tips and tricks
Kubernetes
Delete evicted pods
1
|
kubectl delete pod --field-selector="status.phase==Failed" -n kube-system
|
AWS
How to delete an AWS S3 bucket with 500TB of data
- Log in to the AWS Management Console and navigate to the S3 bucket you want to delete.
- Open the “Lifecycle” configuration tab for the bucket.
- Create a new lifecycle policy, and set the expiration rules to delete objects that are over a certain age or version.
- Set the expiration period to a time frame that makes sense for your data, such as 1day, 2day or 7 days.
- Save the policy and apply it to the bucket.
Get eks nodes AZ
Install https://github.com/awslabs/eks-node-viewer
1
|
eks-node-viewer --extra-labels topology.kubernetes.io/zone
|
Get eks pods AZ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
zones=""
kubectl get nodes --show-labels | tail -n +2 | while read node; do
name=$(echo "$node" | awk '{print $1}')
zone=$(echo "$node" | awk '{print $6}' | awk -F ',' '{for(i=1;i<=NF;i++){print $i}} ' | grep 'failure-domain.beta.kubernetes.io/zone')
zones="$zones\n$( echo $name $zone)";
done
pods=""
kubectl get pods --all-namespaces -o wide --sort-by=.spec.nodeName | while read pod; do
node=$(echo "$pod" | awk '{print $(NF-2)}')
name=$(echo "$pod" | awk '{print $1}')
zone=$(echo "$zones" | grep $node | awk '{print $2}')
pods="$pods\n$( echo $name ${zone//failure-domain.beta.kubernetes.io\//})";
done
echo "$pods" | sort -k2
|
Linux
uptime: command not found
In case if uptime
not installed at all on the system. First value in /proc/uptime
holds uptime in seconds.
1
2
|
root@ee766eb93166:/# cat /proc/uptime
1315448.50 5237909.71
|
Below function converts uptime seconds to more convenient format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
uptime_linux(){
# Try to read uptime from /proc/uptime
uptime_sec=$(cat /proc/uptime 2> /dev/null | awk '{print int($1)}')
# Check if uptime_sec is empty or not a number
if [[ -z "$uptime_sec" || ! "$uptime_sec" =~ ^[0-9]+$ ]]; then
echo "Failed to retrieve uptime."
return 1
fi
# Convert uptime into days, hours, minutes, and seconds
echo "$(date -d "@$uptime_sec" "+$(($uptime_sec/86400)) days and %H hours %M minutes %S seconds")"
}
uptime_linux
|
Output
1
|
15 days and 05 hours 22 minutes 54 seconds
|