Skip to content

Instantly share code, notes, and snippets.

View mvisonneau's full-sized avatar

Maxime VISONNEAU mvisonneau

View GitHub Profile
@mvisonneau
mvisonneau / ami-cost-estimate.sh
Last active April 26, 2023 08:26
AMI cost estimate
#!/usr/bin/env bash
REGIONS=$(aws ec2 describe-regions | jq -r '.Regions[].RegionName' | sort)
TOTAL_SIZE=0
TOTAL_COST=0
for REGION in $REGIONS; do
SIZE=$(AWS_REGION=$REGION aws ec2 describe-snapshots --owner-ids self --query "Snapshots[*].{Description:Description,VolumeSize:VolumeSize}" | jq '[.[] | select( (.Description|startswith("Copied for DestinationAmi")) or (.Description|startswith("Created by CreateImage")) ) | .VolumeSize] | add')
@mvisonneau
mvisonneau / make.sh
Created February 1, 2021 18:07
Compile kubernetes/dns/node-cache
git clone https://github.com/kubernetes/dns.git
cd dns
git checkout 1.17.0
make containers CONTAINER_BINARIES=node-cache
make containers CONTAINER_BINARIES=node-cache ARCH=arm64
docker tag gcr.io/k8s-staging-dns/k8s-dns-node-cache-amd64:1.17.0 mvisonneau/k8s-dns-node-cache-amd64:1.17.0
docker tag gcr.io/k8s-staging-dns/k8s-dns-node-cache-arm64:1.17.0 mvisonneau/k8s-dns-node-cache-arm64:1.17.0
docker push mvisonneau/k8s-dns-node-cache-amd64:1.17.0
docker push mvisonneau/k8s-dns-node-cache-arm64:1.17.0
@mvisonneau
mvisonneau / gen_eni_max_pods.sh
Last active December 19, 2022 10:22
dynamically regenerate eni-max-pods.txt
export AWS_DEFAULT_REGION=eu-west-1
aws ec2 describe-instance-types \
| jq -r --arg FIRST_INTERFACE_INDEX 1 \
'.InstanceTypes[] |
"\(.InstanceType) \(((.NetworkInfo.MaximumNetworkInterfaces-($FIRST_INTERFACE_INDEX|tonumber))*.NetworkInfo.Ipv4AddressesPerInterface)-1)"' \
| sort
# You can also use this uglier one to cap to a certain amount (eg: 110)
# We also remove 2 IPs which are used for cilium router & health
@mvisonneau
mvisonneau / get.sh
Last active May 6, 2020 10:50
Dynamically retrieve all EC2 instance types ENI limits (per region)
aws ec2 describe-instance-types \
| jq '[
.InstanceTypes[] | {
type: .InstanceType,
maxInterfaces: .NetworkInfo.MaximumNetworkInterfaces,
maxIPV4PerInterface: .NetworkInfo.Ipv4AddressesPerInterface,
maxIPV6PerInterface: .NetworkInfo.Ipv6AddressesPerInterface
}
]'
@mvisonneau
mvisonneau / k8s_current_namespace.sh
Created May 1, 2019 16:47
Figure out what is the current namespace configured within the current context using kubectl & jq
kubectl config view -o json | jq -r ".contexts[] | select( .name | contains(\"$(kubectl config current-context)\")) | .context.namespace"

Keybase proof

I hereby claim:

  • I am mvisonneau on github.
  • I am mvisonneau (https://keybase.io/mvisonneau) on keybase.
  • I have a public key ASAnYgnjFyYRTM9h4cm50HzL0-KHzpgDn3VaInODqduNpwo

To claim this, I am signing this object:

{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 0.003723371097,51.53195199 ]
},
"properties": {
@mvisonneau
mvisonneau / vault-aws-ec2-login
Created July 10, 2018 10:50
vault-aws-ec2-login
#!/usr/bin/env bash
if [[ -z ${VAULT_ADDR} ]]; then
echo "VAULT_ADDR must be set"
exit 1
fi
pkcs7=$( curl -s http://169.254.169.254/latest/dynamic/instance-identity/pkcs7 | tr -d '\n' )
iam_instance_profile=$( curl -s http://169.254.169.254/latest/meta-data/iam/info | jq -r .InstanceProfileArn | cut -d '/' -f2 )
nonce=$( openssl rand -base64 36 )
#!/usr/bin/env bash
if ! [ -x "$(command -v git)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
if [ -z "$1" ]; then
echo "Error: you must pass the filename as an argument"
exit 1
@mvisonneau
mvisonneau / bumpme
Last active October 15, 2017 14:14
Sun Oct 15 14:14:30 UTC 2017