Kubernetes time-saving aliases
When preparing for Kubernetes certifications like the CKA or CKAD, saving time during the exam is crucial. One of the best ways to be efficient is by setting up terminal aliases for common kubectl commands. Here is a handy list of time-saving aliases you can use.
General Aliases
These are your standard shortcuts for everyday commands.
alias k='kubectl' # Base command shortcut alias ks='kubectl -n kube-system' # Execute command in the kube-system namespace alias kdesc='kubectl describe' # Describe a specific resource
Create Resources
Use these aliases when creating or applying new resources to your cluster from YAML files.
alias kcf='kubectl create -f' # Create a resource from a file or stdin alias kaf='kubectl apply -f' # Apply a configuration to a resource by filename or stdin
Get Resources
Viewing the status of your cluster is something you will do constantly. Here are some quick commands to fetch pods, nodes, and more.
alias kgn='kubectl get nodes' # List all nodes in the cluster alias kgp='kubectl get pods' # List all pods in the current namespace alias kgpa='kubectl get pods --all-namespaces' # List all pods across all namespaces alias kgs='kubectl get services' # List all services in the current namespace alias kgd='kubectl get deployments' # List all deployments in the current namespace
Delete Resources
When tearing down resources or cleaning up, use these helpful delete aliases to speed up the process.
alias kd='kubectl delete' # Delete a resource by filename, stdin, resource and name alias kdp='kubectl delete pod' # Delete a specific pod alias kds='kubectl delete service' # Delete a specific service alias kdd='kubectl delete deployment' # Delete a specific deployment alias kdn='kubectl delete namespace' # Delete a specific namespace
Setting up these aliases at the very beginning of your session can save you valuable minutes and eliminate repetitive typing during your certification exams!