Skip to content

Instantly share code, notes, and snippets.

Port-forward a k8s service
k port-forward svc/argo-cd-argocd-server 12345:443 -n argocd
Get shell on a pod
k -n [namespace] exec -i -t [argocd server pod name] -- /bin/bash
add --container param for specific container
List all non-running pods
k get pods --field-selector status.phase!=Running -A
@corkupine
corkupine / restartall.ps1
Created February 9, 2023 18:09
Powershell script to restart all deployments and statefulsets in all k8s namespaces
param($kubecontext)
if ($kubecontext -ne $null){
kubectl config use-context $kubecontext
}
else {
$kubecontext = kubectl config current-context
}
$response = Read-Host "Are you sure you want to restart all pods in $kubecontext ? Type YES to continue"
# Based on: https://developer.hashicorp.com/terraform/tutorials/automation/github-actions
name: Terraform plan on PR and apply on merge
on:
pull_request:
types: [opened, closed, synchronize, reopened]
paths:
- "environment/**"
jobs:
terraform_plan:
@corkupine
corkupine / replicateBranch.sh
Created August 4, 2023 14:19
Duplicate all code on another branch with a commit with the diff
#Start out on the branch with the code we want
git checkout branch_a
#create tmp branch same as branch_a (so that we don't change our local branch_a state during the operation)
#working directory has all the code that we want, on tmp branch
git checkout -b tmp
# Change the branch head to the branch we want to be on. All the delta
# between the current source code and branch_b is now staged for commit
git reset --soft branch_b
@corkupine
corkupine / getPodsAndZones.sh
Created August 29, 2023 20:52
Get pods, nodes and zones
#!/bin/bash
kubectl get pods --all-namespaces -o custom-columns=":metadata.namespace,:metadata.name,:spec.nodeName" --no-headers=true | while read -r namespace pod_name node_name
do
zone=$(kubectl get node "$node_name" -o jsonpath="{.metadata.labels.topology\.kubernetes\.io/zone}")
echo "Namespace: $namespace, Pod Name: $pod_name, Node Name: $node_name, Zone: $zone"
done
# This doesn't work well with paging in CLI v2 - do this too:
# export AWS_PAGER=""
BUCKET_NAME=argocdexport
OBJECT_KEY=export.yaml
versions=$(aws s3api list-object-versions --bucket $BUCKET_NAME --prefix $OBJECT_KEY | jq -r '.Versions[].VersionId')
count=`echo $versions |jq 'length'`-1
echo "Retrieved $count versions"
@corkupine
corkupine / ete_cloudflare.sh
Last active March 7, 2024 21:08
Updating ETE tenant config with Cloudflare DNS record IDs
#Get cloudflare dns record IDs for cnames in zescrow.com - redirect to a file
API_KEY="xxxxxxxxxxxxxxxxxx"
ZONE_ID="xxxxxxxxxxxxxxxxxx"
API_URL="https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?type=CNAME"
#Change page as necessary
curl -s -X GET "${API_URL}&page=4" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json"