Skip to content

Instantly share code, notes, and snippets.

View tanelmae's full-sized avatar
🏠
Working from home

Tanel Mae tanelmae

🏠
Working from home
  • Tallinn
  • 07:08 (UTC +03:00)
View GitHub Profile
@tanelmae
tanelmae / test-kube-auth-cmd.sh
Created May 23, 2023 07:06
Test kube auth command
#!/usr/bin/env bash
set -ue
# Resolve config to be used
export KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
export CLUSTER=${1:-$(kubectl config current-context)}
echo "Running against ${CLUSTER}"
# Read auth command from the kubeconfig and use it to get the auth token
CMD_PATH=$(yq '.users | map(select(.name == env(CLUSTER))) | .[] | .user.exec.command' "${KUBECONFIG}")
@tanelmae
tanelmae / ddosify-kubernetes.sh
Created May 22, 2023 12:49
Run ddosify against Kubernetes API
#!/usr/bin/env bash
set -ue
# Resolve config to be used
export KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
export CLUSTER=${1:-$(kubectl config current-context)}
echo "Running against ${CLUSTER}"
# Read auth command from the kubeconfig and use it to get the auth token
CMD_PATH=$(yq '.users | map(select(.name == env(CLUSTER))) | .[] | .user.exec.command' "${KUBECONFIG}")
@tanelmae
tanelmae / ses_password.go
Last active June 3, 2022 10:39
Example how to generate AWS SES password from AWS secret key
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
// AWS documentation: https://docs.aws.amazon.com/ses/latest/dg/smtp-credentials.html#smtp-credentials-convert
@tanelmae
tanelmae / sendmail.go
Created April 26, 2022 18:13
Send email with Go
package main
import (
"flag"
"fmt"
"log"
"net/smtp"
)
func main() {
#!/usr/bin/env bash
# When you really need kubeconfig file inside the pod
cat << EOF
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: $(base64 -w 0 /var/run/secrets/kubernetes.io/serviceaccount/ca.crt)
server: https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
@tanelmae
tanelmae / ingresses-by-class.sh
Created November 24, 2021 10:02
List ingresses with specific class
function ingress-by-class() {
echo "Namespace >> Ingress name"
echo "-------------------------"
kubectl get ingresses \
-o=jsonpath="{range .items[?(@.metadata.annotations.kubernetes\.io/ingress\.class==\"${1}\")]}{@.metadata.namespace}{\" >> \"}{@.metadata.name}{\"\n\"}{end}" --all-namespaces
}
@tanelmae
tanelmae / ingress-report.sh
Last active November 24, 2021 09:59
Kubernetes ingress report
# Lists:
# - number of ingresses
# - number of ingress classes used
# - ingress classes used
# - ingresses without explicit ingress class with name and namespace
# - ingresses by class with name and namespace
# Dependencies: kubectl, jq
function ingress-report() {
echo "Loading ingresses from the cluster"
local INGRESSES=$(kubectl get ingresses -o json --all-namespaces)
@tanelmae
tanelmae / aws-pod-host-ssm.sh
Created November 22, 2021 07:35
Connect to pod host with AWS SSM
function aws-pod-host-ssm() {
local NODE_NAME=$(kubectl get pods ${1} -o go-template='{{.spec.nodeName}}')
local PROVIDER_ID=$(kubectl get node $NODE_NAME -o go-template='{{.spec.providerID}}')
local INSTANCE_ID=${PROVIDER_ID#*//*/*/}
aws ssm start-session --target $INSTANCE_ID
}
@tanelmae
tanelmae / find-secret-usage.sh
Created November 22, 2021 07:34
Find secret from the Kubernetes cluster
# Depends on kubectl and jq
function find-secret-usage() {
local SECRET_CONTENT=${1}
echo "Fetching cluster secrets"
# Spaces removed to ensure each loop iteration gets a valid json object.
# Fields that matter don't have spaces.
local SECRETS=$(kubectl get secrets --all-namespaces -o json | sed -e 's/ //g')
for secret in $(echo ${SECRETS} | jq -rc '.items[]'); do
@tanelmae
tanelmae / asdf-m1.txt
Last active November 22, 2021 07:36
Install amd64 binaries with asdf on Apple M1 machine
# asdf issue ref: https://github.com/asdf-vm/asdf/issues/834
# Switch to x86_64 shell.
# Change the /usr/bin/env bash --login to match whatever shell you use.
/usr/bin/arch -x86_64 /usr/bin/env bash --login
# Install some legacy binaries like this old version of Terraform:
asdf install terraform 0.12.31
# Exit the x86_64 shell and continue using asdf and Terraform as the above never happened :)