Quick tips and tricks
Kubernetes
Delete evicted pods
1
|
kubectl delete pod --field-selector="status.phase==Failed" -n kube-system
|
Get helm diff
1
2
|
helm search repo grafana/promtail --versions --devel
helm template promtail grafana/promtail -n loki -f promtail-ci.yaml --version 6.15.6 --dry-run | kubectl diff -n loki -f -
|
Terminate namespace
1
2
3
4
5
6
|
(
NAMESPACE=your-rogue-namespace
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
)
|
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
|
Packer
No AMI was found matching filters
1
2
3
4
5
6
7
8
9
|
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"root-device-type": "ebs",
"product-code": "aaabbbcccddeee"
},
"owners": ["aws-marketplace"],
"most_recent": true
},
|
1
2
3
4
5
|
aws ec2 describe-images \
--owners ‘aws-marketplace’ \
--filters ‘Name=product-code,Values=ffffgggghhhh’ \
--query ‘sort_by(Images, &CreationDate)[-1].[ImageId]’ \
--output ‘text’
|
MACOS
GUI Network config not sync with /etc/resolv.conf
MACOS cannot resolve remote host, an example below
1
2
|
docker manifest inspect myhost/myimage:latest
failed to configure transport: error pinging v2 registry: Get "https://myhost/v2/": dial tcp: lookup myhost: no such host
|
Update DNS config, so GUI will sync with file /etc/resolv.conf
1
2
3
4
5
6
|
# Active config
scutil --dns
# Get Network service name
networksetup -listallnetworkservices
networksetup -getdnsservers Wi-Fi
sudo networksetup -setdnsservers Wi-Fi 10.10.10.10
|