Skip to content

CKA Notes

CKA Notes published on

General

Usage of documentation is allowed

Cheat sheet. https://kubernetes.io/docs/reference/kubectl/cheatsheet/

Commands

# get persistent volumes (sorted by capacity)
kubectl get pv
kubectl get pv -o yaml
kubectl get pv --sort-by=.spec.capacity.storage

# get services
kubectl get service --all-namespaces

# run a command inside a pod
# use exec, `--` needed because without it is deprecated
kubectl -n beebox-mobile exec quark -- cat /etc/key/key.txt

# apply a deployment
kubectl apply -f deployment.yml

# get all deployments
kubectl get deployments --all-namespaces

kubectl tips

https://kubernetes.io/docs/concepts/overview/working-with-objects/object-management/

Declarative vs Imperative

# declarative, apply a yaml or json
kubectl apply -f deployment.yml 

# imparative
kubectl create deployment my-deployment --image=nginx

# with a dry run you can save create a yaml file:
kubectl create deployment my-deployment --image=nginx --dry-run -o yaml

# imperative command to create a secret from a file:
kubectl create secret generic nginx-htpasswd --from-file .htpasswd
kubectl scale deployment my-deployment --replicas=5

# recording
kubectl scale deployment my-deployment --replicas=5 --record
# you will see the changes in annotations in describe
kubectl describe deployment my deployment

RBAC

https://kubernetes.io/docs/reference/access-authn-authz/rbac/

# apply role based access
kubectl apply -f rbac.yaml

kubectl auth reconcile -f rbac.yaml --dry-run=client
kubectl auth reconcile -f rbac.yaml

# bind user to role, see https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-example, run also with `auth reconcile`

Network Plugin

Installing isn't well described in the current documentation. Could be difficult do find the correct URL to install calico.yaml during CKA exam.

Installation is described at v1.17 docs https://v1-17.docs.kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/. From the course we have this command:

kubectl apply -f https://docs.projectcalico.org/v3.15/manifests/calico.yaml

Troubleshooting network issues: Image nicolaka/netshoot

Metrics

First we have to install metrics server as addon.

# install the file provided by the CKA course
kubectl create -f https://raw.githubusercontent.com/ACloudGuru-Resources/content-cka-resources/master/metrics-server-components.yaml

# check if metrics server is running
kubectl get --raw /apis/metrics.k8s.io/

# use top
kubectl top pod
kubectl top pod -n my-namespace --selector app=xyz --sort-by=cpu