Powerlevel10k - k8s context colors

Having a single kubeconfig with all your kubernetes contexts is a bonus because you can easily switch between contexts pretty quickly using kubectx or mkubectx. On the other hand, this approach has some downsides like pasting the “wrong” command in “wrong” context ie. delete some objects. Subcommand delete in kubectl doesn’t have any confirmation like Unix command rm -i, so we should provide some mechanism to prevent us from doing it. One way is to customize the visualization of our current context in the shell, tool like powerlevel10k comes with help, you can set your own theme for selected Kubernetes contexts just like that:

  typeset -g POWERLEVEL9K_KUBECONTEXT_CLASSES=(
      '*prod*'  PROD
      '*stag*'  STAGING
      '*test*'  TEST
      '*'       DEFAULT)

  typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_FOREGROUND=3
  typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_CONTENT_EXPANSION='> ${P9K_CONTENT} <'
  POWERLEVEL9K_KUBECONTEXT_DEFAULT_CONTENT_EXPANSION+='${${:-/$P9K_KUBECONTEXT_NAMESPACE}:#/default}'

  typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_FOREGROUND=15
  typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_BACKGROUND=28
  typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_VISUAL_IDENTIFIER_EXPANSION=' 🕹️ '
  typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_CONTENT_EXPANSION='${P9K_KUBECONTEXT_CLOUD_NAME}/${P9K_KUBECONTEXT_CLOUD_CLUSTER}/${P9K_KUBECONTEXT_NAMESPACE:-default} '

  typeset -g POWERLEVEL9K_KUBECONTEXT_STAGING_FOREGROUND=231
  typeset -g POWERLEVEL9K_KUBECONTEXT_STAGING_BACKGROUND=172
  typeset -g POWERLEVEL9K_KUBECONTEXT_STAGING_VISUAL_IDENTIFIER_EXPANSION=' 🎹 '
  typeset -g POWERLEVEL9K_KUBECONTEXT_STAGING_CONTENT_EXPANSION='${P9K_KUBECONTEXT_CLOUD_NAME}/${P9K_KUBECONTEXT_CLOUD_CLUSTER}/${P9K_KUBECONTEXT_NAMESPACE:-default} '

  typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_FOREGROUND=15
  typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_BACKGROUND=01
  typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_VISUAL_IDENTIFIER_EXPANSION=' 🖥️ '
  typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_CONTENT_EXPANSION='${P9K_KUBECONTEXT_CLOUD_NAME}/${P9K_KUBECONTEXT_CLOUD_CLUSTER}/${P9K_KUBECONTEXT_NAMESPACE:-default} '

rather self-explanatory with this outcome for a production cluster:

p10k-color1

shell with dark background having a red box should enable more attention ;)

comments powered by Disqus

powered by Hugo and Noteworthy theme