CKA notes

This is my personnal notes from my learning path to the CKA cert. At the time of writing, i have not yet take the exam.

Before everything
source <(kubectl completion bash)
echo “source <(kubectl completion bash)” >> ~/.bashrc alias k=kubectl
complete -F __start_kubectl k
alias k=kubectl

K explain replicaset | grep VERSION

Delete multiple pods (separate with a space)
k delete pods new-replica-set-8fj7n new-replica-set-ghhjm

add replicas
k scale –replicas=5 rs/new-replica-set

Create an NGINX Pod
kubectl run nginx –image=nginx

Generate POD Manifest YAML file (-o yaml). Don’t create it(–dry-run)
kubectl run nginx –image=nginx –dry-run=client -o yaml

Create a deployment
kubectl create deployment –image=nginx nginx

Generate Deployment YAML file (-o yaml). Don’t create it(–dry-run)
kubectl create deployment –image=nginx nginx –dry-run=client -o yaml

Generate Deployment YAML file (-o yaml). Don’t create it(–dry-run) with 4 Replicas (–replicas=4)
kubectl create deployment –image=nginx nginx –dry-run=client -o yaml > nginx-deployment.yaml

Create a Service named redis-service of type ClusterIP to expose pod redis on port 6379
kubectl expose pod redis –port=6379 –name redis-service –dry-run=client -o yaml

kubectl create service clusterip redis –tcp=6379:6379 –dry-run=client -o yaml (This will not use the

Create a Service named nginx of type NodePort to expose pod nginx’s port 80 on port 30080 on the nodes:
kubectl expose pod nginx –type=NodePort –port=80 –name=nginx-service –dry-run=client -o yaml

kubectl create service nodeport nginx –tcp=80:80 –node-port=30080 –dry-run=client -o yaml

Get pods depending on labels
k get pods —selector=tier=frondend, env=prod

Add taint on a node
k taint nodes node1 app =blue:NoSchedule

Show labels on a node
k get nodes node01 —show-labels

Get taint
k describe node kubemaster | grep Taint

Label a node
k label nodes node01 size=Large

Create a static pod with image busy box and command sleep:
kubectl run –restart=Never –image=busybox static-busybox –dry-run=client -o yaml –command — sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

Create a config map
kubectl create configmap webapp-config-map –from-literal=APP_COLOR=darkblue

Put a node in “maintenance mode”
kubectl drain node01 –ignore-daemonsets

Upgrade Kubernetes
On the controlplane node, run the command run the following commands:

  • apt update
  • This will update the package lists from the software repository.
  • apt install kubeadm=1.20.0-00
  • This will install the kubeadm version 1.20
  • kubeadm upgrade apply v1.20.0
  • This will upgrade kubernetes controlplane. Note that this can take a few minutes.
  • apt install kubelet=1.20.0-00 This will update the kubelet with the version 1.20
  • You may need to restart kubelet after it has been upgraded.
  • Run: systemctl restart kubelet

Diplay a certificate
openssl x509 -in /etc/kubernetes/pki/apiserver.crt -text

JSONPath node
kubectl get nodes -o jsonpath='{.items[*].status.addresses
[?(@.type==”InternalIP”)].address}’ > /root/CKA/node_ips

Get Node OS Image
k get nodes -o jsonpath='{.items[1].status.nodeInfo.

Expose deployment
kubectl expose deployment ingress-controller –type=NodePort –port=80 –name=ingress –dry-run=client -o yaml > ingress.yaml

References: kubernetes.io, udemy CKA training course, kodekloud practice.