Tools that make my life easier to work with kubernetes

Naveen
Naveen
Mar 29, 2017 · 2 min read

I work on kubernetes a lot and here are list of tools that makes my life easier to build and manage.

Image for post
Image for post
kubetail
kubetail nginx# filter by containers with in pods 
kubetail l5d -c l5d
Image for post
Image for post
kubernetes context
  • Pimp my context — I work with multiple k8s environments, I would have to know which one I am working with and someone had tweeted this script. I have it in my .oh-my-zsh/themes/agnoster.zsh-theme . This context shows the k8s context and the current namespace.
prompt_kubecontext() {
prompt_segment white black "k8s-`kubectl config current-context`/`kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}'`"
}
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_dir
prompt_git
prompt_kubecontext
prompt_end

}
PROMPT='%{%f%b%k%}$(build_prompt) '
  • Manage Secrets — This is a handy tool to manage secrets in k8s https://github.com/dtan4/k8sec , it always handy to decode secrets instead of doing bunch jq or jsonpath .
#Port forward to linkerd
l5admin(){ kportforward l5d admin app=l5d 9000}
#clean up l5d admin port forwarding
l5clean(){lsof -t -i tcp:9000 | xargs kill}
#Port forward k8s
# $1 servicename
# $2 portname
# $3 pod selector
# $4 local port
kportforward() {
ADMINPORT=$(kubectl get svc $1 -o json |jq '.spec.ports[]| select(.name=="'$2'").port')
POD=$(kubectl get pods --selector $3 \
-o template --template '{{range .items}}{{.metadata.name}} {{.status.phase}}{{"\n"}}{{end}}' \
| grep Running | head -1 | cut -f1 -d' ')
kubectl port-forward $POD $4:$ADMINPORT &
sleep 2
open http://localhost:9000
}
  • kubectl hacks — Some of the kubectl hacks that makes life easier
#copy remote file locally
kubectl cp pod:/remote-file /local/file
#verbose kubectl
kubectl --v=8 version

Google Cloud - Community

Google Cloud community articles and blogs

Naveen

Written by

Naveen

Dad,Husband,Write code.

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Naveen

Written by

Naveen

Dad,Husband,Write code.

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store