0

Kubernetes context per terminal session

If you are like me working with multiple kubernetes clusters it becomes really unhandy to work with them at the same time.

For a while I have been using ktx to manage that – however as mentioned above – at the moment of writing it sets context to be global.

So as a small workaround I have those 2 functions in my `.zshrc` file

k8ctx-switch() { 
# create a temp file for our config 
TEMP_CONFIG="$(mktemp "kubectx.$1")" 
kubectl config view --minify --flatten --context=$1 > $TEMP_CONFIG export KUBECONFIG="${TEMP_CONFIG}:${KUBECONFIG}" cat ${TEMP_CONFIG}
}

k8ctx-list() {
KUBECONFIG="${HOME}/.kube/config" kubectl config get-contexts
}

This is a MVP 🙂 to get multiple tabs opened with different k8s clusters to manage. Pretty handy 🙂

0

Terraform – iam policy for AWS user

Just a quick writeup when for example providing conditional access to s3 you would like to restrict access to AWS user name in the path you can refer to this quick snippet

   statement {
       actions = [
           "s3:ListBucket",
       ]
       resources = [
           "arn:aws:s3:::${var.s3_bucket_name}",
       ]
       condition {
           test = "StringLike"
           variable = "s3:prefix"
           values = [
               "",
               "home/",
               "home/&{aws:username}/",
           ]
       }
   },
   statement {
       actions = [
           "s3:*",
       ]
       resources = [
           "arn:aws:s3:::${var.s3_bucket_name}/home/&{aws:username}",
           "arn:aws:s3:::${var.s3_bucket_name}/home/&{aws:username}/*",
       ]
   }