Tips
These are some tips that can help a lot during the exam.
Completion
Auto-complete for commands is good to set up if it's not working.
sudo apt-get install bash-completion # This is already installed, but if setting up a study environment you will need it.
source <(kubectl completion bash) # autocomplete configuration in the current shell bash, the bash-completion package must be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # to add autocomplete permanently to your bash shell.
echo "source <(kubectl completion bash)" >> ~/.zshrc # to add autocomplete permanently to your zsh shell
echo "source <(etcdctl completion bash)" >> ~/.bashrc # to add autocomplete permanently to your bash shell.
echo "source <(etcdctl completion bash)" >> ~/.zshrc # to add autocomplete permanently to your bash shell.
Aliases
echo "alias k=kubectl" >> ~/.bashrc
echo "alias k=kubectl" >> ~/.zshrc
Exports
We can export some values that help save time.
echo "export dr='--dry-run=client -o yaml'" >> ~/.bashrc
echo "export dr='--dry-run=client -o yaml'" >> ~/.zshrc
echo "export now='--grace-period=0 --force'" >> ~/.bashrc
echo "export now='--grace-period=0 --force'" >> ~/.zshrc
For example, the command kubectl run mypod --image nginx --dry-run=client -o yaml is shortened to kubectl run mypod --image nginx $dr and can be reduced even further with k run mypod --image nginx $dr.
Use Resource Name Abbreviations
k get ns= kubectl get namespacesk get sa= kubectl get serviceaccountsk get svc= kubectl get servicesk get pv,pvc= kubectl get persistentvolumes,persistentvolumeclaim
What to do when starting the exam?
Open Firefox and go to https://kubernetes.io/docs/home/. Bookmark it so you don't have to type it again.
Open the terminal and type all the commands above to ensure that if you close the terminal again, it comes back with everything you need already configured.
Keep more than one terminal tab open. Use the second tab for ssh commands that you will likely have during the exam.
The answers to questions 1, 2, 3... are in /opt/course/1, /opt/course/2, /opt/course/3...
So start by putting the terminal in the right place even before reading the question.
cd /opt/course/1/
Avoid Silly Mistakes
- In the header of all questions there will be a command to switch to the correct cluster. Even if it's the same as the previous cluster, copy, paste and execute to be sure
- Whenever a resource name is given, whether namespace, pod, deploy, image, commands or anything else that can be copied and pasted, do copy/paste to avoid typing errors
- Always observe the namespace being requested. For each command think, am I in the correct namespace? Another way is to always switch to the specific namespace for the question using
kubectl config set-context --current --namespace NAMESPACE-NAME - Check the results of what you applied to the cluster before moving to another question
Monitor Time
If the exam has between 15 and 20 questions in 120 minutes, the average time per question is between 6 and 9 minutes. Try to study while tracking this average time per question.
On low-weight questions you should be able to save time for higher-weight questions. Think about it.
Linux Commands
-
wc -l: to count lines. Remember to remove the headers from Kubernetes output.kubectl get pods -n kube-system --no-headers | wc -l
12 -
awk '{print $1}: where $1 is the column to print from the output usually from a grep you did.kubectl get pods --no-headers
mydeploy-569bfcf767-ssxl6 1/1 Running 0 11m
kubectl get pods --no-headers | awk '{print $1}'
mydeploy-569bfcf767-ssxl6 -
tr " " "\n": replacing spaces with a new line. -
curl -s ip:port: in this example we are trying to connect using ip:port via curl. It's good to have this command ready to test communication between pods if necessary.echo "this is a test" | tr " " "\n"
this
is
a
test -
ssh:Execute a command using ssh on a machine without needing to be inside it to get the output.ssh <your-user>@<ip-address> "<command>" &> output.txt
Save time by finding documentation quickly
Keywords:
- persistent volume
- toleration
- nodeSelector
- affinity
- fieldRef
- Upgrading kubeadm clusters
- kubelet
- network-policies
- etcd
- liveness and readiness probe
- configmap
- securitycontext
- share storage
Commands that should be memorized
kubectl config get-contexts -o name
kubectl config use-context kind-kind-cluster-ia
kubectl config set-context --current --namespace kube-system
kubectl config current-context
cat ~/.kube/config | grep current-context | awk '{print $2}' # Another method
# --dry-run=client -o yaml > manifest.yaml - This could be used to redirect the output of the commands below as a simulation
kubectl run mypod --image nginx --labels=id=1234,env=prod
kubectl create deploy --image nginx --replicas 2
kubectl get pods --sort-by metadata.name
kubectl get pods --sort-by metadata.name -o custom-columns=NAME:.metadata.name
kubectl get pods --sort-by metadata.name -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName
# Filter pods in all namespaces that have the passed label and field as well
kubectl get pods --all-namespaces --selector k8s-app=kube-dns --field-selector=spec.nodeName=kind-cluster-ia-control-plane -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system coredns-76f75df574-82xg7 1/1 Running 0 23h 10.244.0.3 kind-cluster-ia-control-plane <none> <none>
kube-system coredns-76f75df574-p5jzh 1/1 Running 0 23h 10.244.0.2 kind-cluster-ia-control-plane <none> <none>
kubectl auth can-i
What should be at your fingertips
Storage
- For pv and pvc we need to understand hostPath well since it's unlikely they'll have something different on the exam
- For pods understand emptyDir well for communication between pods
APIs
kubectl api-resources --namespaced=true -o name
If a cluster update question comes up, leave it for last.