Useful aliases to create when interacting with a Kubernetes cluster
When we work on Kubernetes projects, we very regularly have to execute some kubectl commands. To save time, we created a list of aliases on our servers that, not surprisingly, made it easier for us to interact with our Kubernetes clusters.
Below a list we compiled some of the most useful aliases we created:
get_bo='kubectl -n app-prd get pods -l app=app-bo'
get_fo='kubectl -n app-prd get pods -l app=app-fo'
get_pods='kubectl get pods -n app-prd -o wide'
get_varnish='kubectl -n app-prd get pods -l app=varnish'
ssh_bo_fpm='kubectl -c app-fpm -n app-prd -it exec $(kubectl -n app-prd get pods -l app=app-bo -o json | jq -r .items[0].metadata.name) -- bash'
ssh_bo_nginx='kubectl -c app-nginx -n app-prd -it exec $(kubectl -n app-prd get pods -l app=app-bo -o json | jq -r .items[0].metadata.name) -- bash'
ssh_fo_fpm='kubectl -c app-fpm -n app-prd -it exec $(kubectl -n app-prd get pods -l app=app-fo -o json | jq -r .items[0].metadata.name) -- bash'
ssh_fo_nginx='kubectl -c app-nginx -n app-prd -it exec $(kubectl -n app-prd get pods -l app=app-fo -o json | jq -r .items[0].metadata.name) -- bash'
ssh_varnish='kubectl -c varnish -n app-prd -it exec $(kubectl -n app-prd get pods -l app=varnish -o json | jq -r .items[0].metadata.name) -- bash'
varnish_flush='kubectl -n app-prd get pods -l app=varnish -o name | xargs -I{} kubectl -c varnish -n app-prd exec {} -- varnishadm "ban req.url ~ ."'