Tales of engineers

k8s, aliases and frustation

I am not sure about you… but, after a few bi-zillions times running the same:

				
					k logs -f  POD_NAME
				
			

And get the error about the default container, so, you have to choose one, and then… run it again…. I wrote this:

				
					function klogs() {
        get_pod=$(kubectl get pods|awk '{print $1}' | fzf)
        get_container=$(kubectl get pods ${get_pod} -o jsonpath='{.spec.containers[*].name}'  | tr -s '[[:space:]]' '\n' |fzf  )
        kubectl logs -f ${get_pod} -c ${get_container}
}
				
			

You need https://github.com/junegunn/fzf , and will just give you a chance choose from the containers in the pod.

Same has happen times enough in my life with cm, so, I did the same for those:

				
					function kecm() {
        get_cm=$(kubectl get cm|awk '{print $1}' | fzf) kubectl edit cm ${get_cm} 
}
				
			

Deja una respuesta

Tu dirección de correo electrónico no será publicada.