César D. Velandia

CKA Tips


Introduction

Why you should get the CKA?

How is it different from the Application Developer Certification?

My study plan

Schedule

Resources

Hands-on and exam simulations

Tips

While preparing

1. Take sufficient notes

2. Take a few simulations, not too many

3. Prepare your exam environment

4. Practice on a web terminal

On the exam day

1. Use tmux

2. Set some aliases

I usually type kubeclt instead of kubectl and I've seen many make several similar typos, Add alias k=kubectl is a good idea and even recommended in the the documentation. Other aliases I use are:

alias k=kubectl
alias kg="kubectl get -o wide --show-labels"
alias kc="kubectl create -o yaml --dry-run=client"
alias ka="kubectl apply -f "
complete -F __start_kubectl k

These command can increase your speed, but may cost you in accuracy if you used blindly, I suggest the following loop:
i. Use kg to understand the current state of the objects, pods, deployments services or simply do kg all

ii. Issue an imperative command and print it to console using kc so for example: kc deploy myapp --image=nginx gets you a quick view of the specification, from there you can either export it to a file > myapp.yaml for further processing or apply the spec.  

kc deploy myapp --image=busybox --command -- sleep 9999 > myapp.yaml

kc deploy myapp --image=nginx | ka -

iii. Verify that the changes have been applied, e.g., kg po -w will follow up status changes for pods in the default namespace.

Combine kg with all shorthand resource identifiers and selectors:

kg pod -A # --all-namespaces
kg po,svc,ep,pv,pvc -n kube-system
kg pv -l app=db
kg po --sort-by=.metadata.name

k run is a little less expressive in the latest version here  and yet will allow you to assemble a template very quickly

# create a quick template for deployments or pods, e.g.,

k run my-pod --image=busybox --command -- sleep 9999

Use kc on these resources:

clusterrole, clusterrolebinding, configmap, deployment, job, namespace, poddisruptionbudget, priorityclass, quota, role, rolebinding, secret, service, serviceaccount

kc deploy my-deploy --image=nginx

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: my-deploy
  name: my-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-deploy
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: my-deploy
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

# use scale or modify the template before applying
kubectl scale deploy/my-deploy --replicas=2

3. Utilize resource shorthands


+-------------+-----------------------------+
| Short name  |          Full name          |
+-------------+-----------------------------+
| csr         | certificatesigningrequests |
| cs          | componentstatuses           |
| cm          | configmaps                  |
| ds          | daemonsets                  |
| deploy      | deployments                 |
| ep          | endpoints                   |
| ev          | events                      |
| hpa         | horizontalpodautoscalers   |
| ing         | ingresses                   |
| limits      | limitranges                 |
| ns          | namespaces                  |
| no          | nodes                       |
| pvc         | persistentvolumeclaims      |
| pv          | persistentvolumes           |
| po          | pods                        |
| pdb         | poddisruptionbudgets        |
| psp         | podsecuritypolicies         |
| rs          | replicasets                 |
| rc          | replicationcontrollers      |
| quota       | resourcequotas              |
| sa          | serviceaccounts             |
| svc         | services                    |
+-------------+-----------------------------+

Find them all in the official docs here.

4. Install  and use yq

In an ubuntu machine simply run snap install yq is a nifty YAML validation tool that will help you find your mistakes easily.

5. Make VIM yaml friendly

Make sure to autogenerate your templates with this combo as much as you can:
kc deploy .... > app.yaml

However you will still need VIM to tweak your yaml. An easy way to achieve this is by adding the following line to your ~/.vimrc file:

autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab

Tabs will be converted into 2 spaces, very useful when copying and pasting from the documentation (or use :set paste inside VIM). I also find useful to use :set retab when I've copied tabs by mistake.

6. Use kubernetes.io search tool

Part of the Kubernetes resources is the search tool which can be used as intended to find specific pages in the documentation, another way to use it is to by making use of the results page excerpts themselves.

If you are forgetting a port, a URL and know of a search that may yield results, you should be able to peek in around and find what you need. See this example:

https://kubernetes.io/search/?q=etcdctl

You can see in the results an excerpt with command required to save snapshots via etcdctl without even have to click on the results.