My k8s howtos
At work, we deploy on Kubernetes clusters using terraform. From a developer perspective, from writing code to running in production, those technologies make it incredibly fast. Yet sometimes it can takes you hours or even days of random roundtrips between CI/CD, small terraform changes and reading logs. Some tasks are not easy to do, or well, you have to remember how to do them because you don't perform them very often. So, here is my log of useful commands.
How to copy a secret from a namespace to another one
kubectl --context sourceContext get secret mySecret -o yaml | sed 's/namespace: .*/namespace: targetNamespace/' | kubectl --context targetContext apply -f -It simply fetches in YAML the secret we want to copy, then replace in that YAML the namespace to be the destination namespace and use that transformed YAML file to perform an apply which will create the secret in the desired namespace. Easy.
How to retrieve locally thread and fiber dumps from a pod
Sometimes you run into a deadlock in production and you want to know more. On the JVM you can inspect thread dumps and if your app is written in Scala with cats-effect, you can also have fiber dumps. Analyzing those can help with troubleshooting a deadlock.
# on local machine
kubectl --context <ctx> -n <ns> logs --since=5s -f <pod> > dump.log &
# On remote host - assuming running pid is 1
# to get Fiber dump (cats-effect)
kill -USR1 1
# to get thread dump (any jvm app)
kill -3 1
# back on local machine
kill %1
Basically POSIX signals to use are:
USR1to get fiber dumps on Cats-effect runtimeINFOto get fiber dumps on ZIO runtime (Macos only ?)SIGQUITto get a thread dump