CKA Exam Prep Flashcards
(103 cards)
What is the command to create a POD?
kubectl run pod_name –image=image_name
What is the command to create a POD manifest file without creating the resources?
kubectl run pod_name –image=image_name –dry-run=client -o yaml
How to create a deployment?
kubectl create deployment deployment_name –image=image_name
e.g. kubectl create deployment my-nginx –image=nginx
This creates a Deployment named my-nginx that runs Pods using the nginx image. Kubernetes will automatically ensure that one instance of the nginx container is running unless scaled otherwise.
Kubernetes automatically assigns labels as well to the pod and uses those as selectors in deployment
Create deployment with 4 replicas
kubectl create deployment deployment_name –image=image_name –replicas=4
e.g.: kubectl create deployment nginx –image=nginx –replicas=4
How to scale a deployment
kubectl scale deployment deployment_name –replicas=6
e.g.: kubectl scale deployment nginx –replicas=4
How to create a namespace?
kubectl create namespace namespace_name
e.g. kubectl create namespace dev
How to create a POD in a specific namespace
kubectl run pod_name –image=image_name –namespace=namespace_name
e.g. kubectl run nginx –image=nginx –namespace=dev
How to edit a resource?
kubectl edit resource_type resource_name
e.g.
kubectl edit deployment deployment_name
kubectl edit pod pod_name
This edits the in-memory file and changes the resources but the main config file is untouched
How to apply a configuration file?
kubectl apply -f config_file.yaml
How to set a new image for an existing deployment?
kubectl set image deployment/deployment_name image_name=new_image_name
e.g. kubectl set image deployment/my-deployment nginx=nginx:1.21
This command directly modifies the configuration of the Deployment in the Kubernetes cluster. It creates a rolling update where Pods are gradually replaced with new Pods using the updated image.
How to describe a resource?
kubectl describe pod pod_name
How to view logs
kubectl logs pod_name
How to get resources? pods, services, deployments, namespaces, nodes
kubectl get pods
kubectl get services
kubectl get deploymnets
kubectl get nodes
kubectl get all
How to see resources for all namespaces?
kubectl get all –all-namespaces
How to get resources with wide output?
kubectl get pods -o wide
How to delete a deployment?
kubectl delete deployment deployment_name
How to create a resource file for deployment from Live configuration?
kubectl get deployment deployment_name -o yaml > deployment.yaml
How to dry run to generate a YAML file? Consider a deployment
kubectl create deployment deployment_name -image=image_name –dry-run=client -o yaml
How to update objects within a configuration file?
kubectl replace -f config_file.yaml
you can use kubectl apply -f config_file.yaml
How to apply resources in a directory instead of specific file?
kubectl apply -f /path/to/config-files
Does deployments automatically create all the resources including replica sets?
Yes
How to check the rollout status of a deployment?
kubectl rollout status deployment/deployment_name
How to check the rollout history of a deployment?
kubectl rollout history deployment/deployment_name
How to undo a rollout for a deployment?
kubectl rollout undo deployment/deployment_name