List of assigned IPs in subnet
EC2: List of assigned IPs in subnet
aws ec2 describe-network-interfaces
--filters "Name=subnet-id,Values=<subnet-id>"
--query 'NetworkInterfaces[*].PrivateIpAddress'
How to make EC2 user data script run again on startup?
How to make EC2 user data script run again on startup?
rm /var/lib/cloud/instances/*/sem/config_scripts_user
rm /var/lib/cloud/instance/sem/config_scripts_user
Docker clean up
docker system prune --all --volumes --force
docker volume rm $(docker volume ls -qf dangling=true)
docker rm -vf $(docker ps -aq)
docker rmi -f $(docker images -aq)
docker volume prune -f
Stop all containers
docker stop $(docker ps -qa)
Remove containers
docker rm $(docker ps -qa)
Remove all images
docker images -q |xargs docker rmi
docker rmi -f $(docker images | grep "<none>" | awk "{print \$3}")
Docker network change default
systemctl stop docker
iptables -t nat -F POSTROUTING
ip link set dev docker0 down
ip addr del 172.17.0.1/16 dev docker0 # delete old route
ip addr add 172.18.32.1/24 dev docker0 # add new one
ip link set dev docker0 up
Permanent options : /etc/default/docker
DOCKER_OPTS : /etc/docker/daemon.json
--bip=172.18.32.1/24 --default-gateway=172.18.32.1
{
"default-address-pools": [
{"base":"172.80.0.0/16","size":24},
{"base":"172.90.0.0/16","size":24}
]
}
Export DB dump of a particular database to your machine
Export DB dump of a particular database to your machine
$ kubectl exec {{podName}} -n {{namespace}} -- mysqldump -u {{dbUser}} -p{{password}} {{DatabaseName}} > <scriptName>.sql
# Example :
$ kubectl exec mysql-58 -n sql -- mysqldump -u root -proot USERS > dump.sql
Find all images inside containers
Find all images inside containers
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
Get Limit Requests for all containers
Get Limit Requests for all containers
kubectl get pod --all-namespaces --sort-by='.metadata.name' -o json | \
jq -r '[.items[] | {pod_name: .metadata.name, containers: .spec.containers[] | \
[ {container_name: .name, memory_requested: .resources.requests.memory, cpu_requested: .resources.requests.cpu} ] }]' | \
jq 'sort_by(.containers[0].cpu_requested)'
K8S list all container's image from a cluster
Kube (K8S) list all container’s image from a cluster
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
kubectl check secrets certificates
kubectl check secrets certificates
kubectl get secret CERTNAME -o "jsonpath={.data['tls\.crt']}" | base64 -D | openssl x509 -enddate -noout
kubectl basic commands
kubectl basic commands
# connect on Pods
kubectl exec -it --namespace=develop my-pod-id -- /bin/ash
# Show pod network on cluster
kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'
# Show Pods by <node>
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>
# sorting pods
kubectl get pods -o wide --sort-by="{.spec.nodeName}"
kubernetes volume protected
kubernetes volume protected
This happens when persistent volume is protected. You should be able to cross verify this:
Command:
kubectl describe pvc PVC_NAME | grep Finalizers
Output:
Finalizers: [kubernetes.io/pvc-protection]
You can fix this by setting finalizers to null using kubectl patch:
kubectl patch pvc PVC_NAME -p '{"metadata":{"finalizers": []}}' --type=merge
EKS CPUthrotting
docker run --cpus CPUS -it python python -m timeit -s 'import hashlib' -n 10000 -v 'haslib.sha512().update(b"foo")'
Syntax of IP linux command
ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help
Understanding ip command OBJECTS syntax OBJECTS can be any one of the following and may be written in full or abbreviated form:
(image)[/posts/introduction/hero.svg]
You can select between IPv4 and IPv6 using the following syntax:
```shell
### Only show TCP/IP IPv4 ##
ip -4 a
### Only show TCP/IP IPv6 ###
ip -6 a
It is also possible to specify and list particular interface TCP/IP details:
### Only show eth0 interface ###
ip a show eth0
ip a list eth0
ip a show dev eth0
### Only show running interfaces ###
ip link show up