Skip to content

Instantly share code, notes, and snippets.

Avatar

Petr Ruzicka ruzickap

View GitHub Profile
@ruzickap
ruzickap / remove_zone_route53.sh
Created Nov 15, 2020
Remove DNS Zone form AWS Route 53 (including all zone records)
View remove_zone_route53.sh
ZONE_NAME="test.example.com"
ZONE_ID=$(aws route53 list-hosted-zones --query "HostedZones[?Name==\`${ZONE_NAME}.\`].Id" --output text)
aws route53 list-resource-record-sets --hosted-zone-id "${ZONE_ID}" | jq -c '.ResourceRecordSets[] | select (.Type != "SOA" and .Type != "NS")' |
while read -r RESOURCERECORDSET; do
aws route53 change-resource-record-sets \
--hosted-zone-id "${CLUSTER_FQDN_ZONE_ID}" \
--change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet": '"${RESOURCERECORDSET}"' }]}' \
--output text --query 'ChangeInfo.Id'
done
@ruzickap
ruzickap / k8s_get_pod_count_per_nodes.sh
Created Aug 28, 2020
Show number of containers running on all the worker nodes in Kubernetes
View k8s_get_pod_count_per_nodes.sh
GET_NODES=$(kubectl get node -o=custom-columns='NAME:metadata.name' | grep -v ^NAME)
for NODE in ${GET_NODES}; do
echo -en "${NODE}:\t"
kubectl get po --field-selector=status.phase=Running --all-namespaces -o json | jq -r ".items[] | select(.spec.nodeName==\"${NODE}\") | .metadata.name" | wc -l
done
@ruzickap
ruzickap / headset.sh
Created Aug 20, 2020
Move all sound output to Headset
View headset.sh
#!/bin/bash -eu
HEADSET=$(pacmd list-sinks | sed -n 's/.*name: <\(.*output.*Headset.*\)>/\1/p')
HEADSET_MIC=$(pacmd list-sources | sed -n 's/.*name: <\(.*input.*Headset.*\)>/\1/p')
pacmd "set-default-sink ${HEADSET}"
pacmd "set-default-source ${HEADSET_MIC}"
pactl set-sink-mute "${HEADSET}" 0
pactl set-sink-volume "${HEADSET}" 80%
@ruzickap
ruzickap / install_raspap.sh
Created Aug 20, 2020
Script for quick installation of RaspAP
View install_raspap.sh
#!/bin/bash -eux
DEVICE="sdc"
lsblk --output NAME,MODEL,MODEL | grep ${DEVICE}
read -r -p "Press enter to remove everything from ${DEVICE}"
curl -L https://downloads.raspberrypi.org/raspios_lite_armhf_latest | zcat | sudo dd of=/dev/${DEVICE} bs=4M
sudo partprobe /dev/${DEVICE}
@ruzickap
ruzickap / aws_route53_subdomain.sh
Created May 6, 2020
AWS Route53 subdomain delegation
View aws_route53_subdomain.sh
# You have defined the "cna.example.cloud" zone in Route53
# You want to create subdomain "${USER}-k8s.cna.example.cloud" and configure proper delegation form parrent zone
echo "* Create DNS zone ${USER}-k8s.cna.example.cloud"
aws route53 create-hosted-zone --output json \
--name ${USER}-k8s.cna.example.cloud \
--caller-reference "$(date)" \
--hosted-zone-config="{\"Comment\": \"Created by ${USER}@example.com\", \"PrivateZone\": false}" | jq
@ruzickap
ruzickap / Deploy public ssh key from GitHub user
Last active Dec 18, 2020
deploy-public-ssh-key-github.sh
View Deploy public ssh key from GitHub user
GITHUB_USERNAME="${GITHUB_USERNAME:-ruzickap}"
DESTINATION_DIRECTORY="${DESTINATION_DIRECTORY:-/root/.ssh}"
[[ ! -d "${DESTINATION_DIRECTORY}" ]] && mkdir -v --mode=0700 "${DESTINATION_DIRECTORY}"
wget "https://github.com/${GITHUB_USERNAME}.keys" -O "${DESTINATION_DIRECTORY}/authorized_keys"
chmod 0600 "${DESTINATION_DIRECTORY}/authorized_keys"
@ruzickap
ruzickap / k8s-debug.sh
Created Mar 21, 2020
Kubernetes debug notes
View k8s-debug.sh
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl logs -n monitoring prometheus-prometheus-operator-prometheus-0 --all-containers
@ruzickap
ruzickap / check_urls.sh
Last active Feb 2, 2020
Automatically check links on web pages
View check_urls.sh
git clone git@github.com:ruzickap/check_urls.git
cd check_urls
mkdir -p .github/workflows
cat > .github/workflows/periodic-broken-link-checks.yml << \EOF
name: periodic-broken-link-checks
on:
schedule:
- cron: '0 0 * * *'
@ruzickap
ruzickap / git-repository-gpg-crypt
Created Nov 1, 2019
Make git repository encrypted with generated GPG key which can be used by CI/CD to access the git repo when using GitHub Actions
View git-repository-gpg-crypt
# Make sure you are using gpg2
git config --global gpg.program gpg2
# Clone empty repository
git clone git@github.com:ruzickap/terraform-gitops.git
# Configure a repository to use git-crypt
cd terraform-gitops
git-crypt init
View kubernetes_notes.sh
# Connect to PostgreSQL database internally
kubectl run -i --tty --rm psql --image=postgres --env "PGPASSWORD=user_password" --command -- \
psql -U myuser -h patroni.patroni.svc.cluster.local my_database
# Port forwarding to service
kubectl port-forward -n harbor service/harbor 8080:443