Skip to content

Instantly share code, notes, and snippets.

@mtilson
mtilson / README.md
Created March 26, 2024 14:12
How different yaml constructions for k8s pod's 'command' and 'args' influence container 'cmdline'

Option 1 - WORKING

deploy.yaml content

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tpd
spec:
@mtilson
mtilson / README.md
Last active September 17, 2022 16:41
how to approach to multi-environment with helm value structure [helm] [nginx] [k8s]

How to define and reference different helm values depending on the environment being deployed

Approach 1

  • Using environment slug to determine environment variable values from helm values structure for multi-environment configuration

Directory structure

$ tree
@mtilson
mtilson / _commands_output.txt
Last active September 8, 2022 17:42
how to deal with CIDRs in different AWS availability zones with terraform 'cidrsubnet' function [aws] [terraform]
$ terraform init
Initializing modules...
- eun1 in module
- euw2 in module
- use1 in module
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 4.27.0"...
@mtilson
mtilson / README.md
Last active July 5, 2022 07:37
how to setup static DNS servers in DHCP environment [ubuntu 18.04] [bash] [systemd] [systemd-networkd] [systemd-resolved]

How to setup static DNS servers in DHCP environment for Ubuntu 18.04

Enable systemd-networkd debugging

$ sudo mkdir -p /etc/systemd/system/systemd-networkd.service.d/

$ sudo cat > /etc/systemd/system/systemd-networkd.service.d/05-enable-debugging.conf << _EOF
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
@mtilson
mtilson / .vimrc
Created June 26, 2022 06:55
short snippet for vimdiff suitable colours [vim] [vimdiff]
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
@mtilson
mtilson / command.sh
Last active November 4, 2021 15:51
how to filter docker containers by their age [docker] [bash]
# show containers in 'exited' state created more than 10 days ago (240 hours)
# change STATE to the requested container state, can be 'exited', 'created' or 'running'
# change HOURS to the requested time in hours
docker container ls -a --format \
'HOURS=240; STATE=exited; TIME_CREATED="{{.CreatedAt}}";
if [[ {{.State}} = $STATE ]]; then
TIME_CREATED=$(date -d "${TIME_CREATED% *}" +%s);
TIME_POINT=$(($(date '+%s')-$HOURS*3600));
if [[ $TIME_CREATED -lt $TIME_POINT ]] ; then
echo "{{.ID}}|{{.Names}}|{{.RunningFor}}" ;
@mtilson
mtilson / 00-script.sh
Last active October 17, 2021 16:56
how to get PKI JWT token and verify it using CLI
# generate RSA private key
openssl genrsa -out 01-key.pem
# get corresponding public key
openssl pkey -in 01-key.pem -inform pem -out 02-pub.pem -outform pem -pubout
# get JWT header
echo -n '{"alg":"RS256","typ":"JWT"}' > 03-header.json
# make sure the content doesn't have trailing newline
@mtilson
mtilson / command.sh
Created September 22, 2021 23:24
how to list all route53 A records
aws route53 list-hosted-zones | jq '.HostedZones[].Id' | tr -d '"' | while read zone ; do
echo "== $zone"
aws route53 list-resource-record-sets --hosted-zone-id $zone --query "ResourceRecordSets[?Type == 'A']" | \
grep '"Name":\|DNSName\|Value' | \
sed -e 's/ //g' | \
sed -n -f route53.sed
done
@mtilson
mtilson / script.sh
Last active April 6, 2021 10:02
how to merge kubeconfig files [k8s]
cd $(mktemp -d)
# `./config` - existent kubeconfig to merge to (like ~/.kube/config)
# `./configToAdd` - new kubeconfig to merge from
cat <<_EOF_ > ./config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: MQo=
@mtilson
mtilson / README.md
Last active June 1, 2022 18:51
how to get external IP on different clouds [linux] [aws] [gcp]

Common methods for AWS EC2 and GCP GCE

# AWS
$ dig +short myip.opendns.com @resolver1.opendns.com
18.224.203.147
# GCP