CKA - You Got this! - Post 3: Command line tips - built for speed

This is the third and final of the blog post series on prepping for the CKA exam - CKA: You Got this!

In the first post we covered the curriculum and the format of the exam.
In the second post, we delved deeper into the topics areas of the exam by providing some key training materials references for each section.

Having completed your preparation,  thoughts should be turning to the exam itself and how best to perform during it. Remember, it is a timed exam, and time is precious.

In this post we will outline some incisive command line tips that should save time in the exam.

We will focus on editor set ups, shell shortcuts and finally kubectl commands.

So lets go.

text editor 

The text editor in the exam is super important. vi is available so the rest of this post will focus on this editor.
A lot of time in the exam is spent editing manifests - in yaml mainly , or json if you prefer,  in the vi its key that you can navigate your way quickly around these files. Here are some points on the usage of vi that are useful for the exam:
  • Sounds obvious but understand how to cut and paste into vi. Make sure content is preserved in correct format (i.e. yaml spacing)
  • Understand key strokes that behave as shortcuts - like gg, G - these help you to navigate around the yaml files so that you can edit these quickly 
  • Understand how to functions like shifting/copying/deleting blocks of code left & right
A great resource for figuring some of this stuff out is here.


Just as important during the exam are terminal commands and how you can speed these up.
Only a single terminal console is available during the exam. Terminal multiplexers such as GNU Screen and tmux can be used to create virtual consoles. But we will focus on the single terminal in this blog post.

We mentioned in previous posts that a lot of the time in the exam is spent writing kubectl commands - of various types, doing many different things.
Here are some tips that we consider vital in minimising repetitive typing that eats into your exam time
  • use aliases for kubectl and extensions of this i.e. alias k=kubectl will mean you just type 'k' instead of kubectl (every second counts !) ; but don't stop there! go alias crazy! Useful aliases include those for 'kubectl get pods' , 'kubectl get deployments' ; 'kubectl get nodes' which could look like kgp, kgd and kgn and so on
  • enable bash completion for kubectl to save on completing commands manually. This is done by adding :       source < (kubectl completion bash)   to your bash profile


  • make use of the help function that is available with kubectl. 'kubectl --help' on the command line will return all its option parameters. See a sample output below.

    • This is very useful. Primarily it means you don't have switch windows to refer to the docs, but instead can stay on the command line and get what you need.  
  • The output of 'kubectl --help' can be searched for the syntax of particular commands. For example, if you need to perform a 'run ' command , then 'kubectl run --help | grep kubectl' will return a list of commands for kubectl and can be a quick way of getting the specific command syntax you need. See below

  • use --dry-run with kubectl to create a manifest file for the type of resource you need, without actually creating the resource. For example ' kubectl run nginx --image=nginx --dry-run -o yaml > deployment.yaml '  will create a sample manifest for a deployment. 
  • make use of the restart parameter in the kubectl command to create either a deployment, pod or job. The restart option has three valid values - Always, Never and OnFailure (with Always being the default value) which when specified to the kubectl command, dictates the resource created. For example 
    • 'kubectl run optest --image=nginx --restart=Never' --> creates a pod called optest
    • 'kubectl run optest --image=nginx --restart=OnFailure' --> creates a job called optest
    • 'kubectl run optest --image=nginx ' --> creates a deployment called optest ( restart value not specified so the default 'Always' is used
         This is a another time saving feature as it allows you create different resources with very                     similar  commands.

So there you have it. We hope you find these time saving tips and tricks useful. Time is precious and every second counts in the exam and so we hope our tips will help you get some of that time back.