Cheat sheet
记录平时可能用到的,有点tricky的命令
jq
## get specify region ip-range in aws ip-ranges json
cat ip-ranges.json| jq -r '.prefixes[] | select(.ip_prefix != null and .region == "ap-southeast-1")| [.ip_prefix, .region, .service, .network_border_group] | @csv'
k8s
- run temporary pods
## node selector/tolerations/pullSecret
kubectl run tmp-shell --rm -i --tty --image travelping/nettools \
--overrides='{ "spec": { "nodeSelector": { "cloud.google.com/private-node": "true" } , "imagePullSecrets": [{"name": "YOUR_SECRET_NAME"}], "tolerations": [{ "key": "node.kubernetes.io/unschedulable", "operator": "Exists", "effect": "NoSchedule" }] } }' -- /bin/bash
- port-forward things, convenient for debug
# Listen on port 5000 on the local machine and forward to port 6000 on my-pod
kubectl port-forward my-pod 5000:6000
# listen on local port 5000 and forward to port 5000 on Service backend
kubectl port-forward svc/my-service 5000
# listen on local port 5000 and forward to Service target port with name <my-service-port>
kubectl port-forward svc/my-service 5000:my-service-port
# listen on local port 5000 and forward to port 6000 on a Pod created by <my-deployment>
kubectl port-forward deploy/my-deployment 5000:6000
- awk things
awk '{sum+=$2} END{print sum}'
awk '{a[$2]+=$4}END{for(i in a){print i" "a[i]}}'
awk '$NF!~"Amazon" {sum+=$4} END{print sum}'
- other
## get tfstat file in tofu controller deployed in k8s
kubectl get secret $1 -o jsonpath={.data.tfstate} | base64 -d | gzip -d | jq '.resources[0,1].instances[0].attributes'