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:
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.
osImages}’
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.
Lead Consultant for ITQ based in the south of France.
Don’t miss our future updates! Get Subscribed Today!
©2022 Copyrights FLORIAN CASSE All Rights Reserved.