Created
February 12, 2022 08:54
-
-
Save amarjitdhillon/55edf95d350a9b3618d49b69774baca2 to your computer and use it in GitHub Desktop.
CKAD exam cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl set image pod podname nginx=nginx:1.15-alpine | |
kubectl edit pod podName | |
# Create the nginx pod with version 1.17.4 and expose it on port 80 | |
kubectl run nginx --image=nginx:1.17.4 --restart=Never --port= | |
kubectl run nginx-pod --image=nginx:alpine # will create a pod with name nginx-pod | |
# add the command in the pod | |
command: ['sleep', '5000'] | |
# adding args | |
args: ['--color', 'green'] | |
kubectl logs nginx # get logs | |
kubectl logs nginx -p # get previous logsj of the pod | |
kubectl exec -it nginx -- /bin/sh | |
kubectl exec -it nginx -- /bin/sh -c 'echo hello world' | |
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm | |
# set an env variable | |
kubectl run nginx --image=nginx --restart=Never --env=var1=val1 | |
# get the env variable using exec | |
kubectl exec -it nginx -- env | |
# create a secret and add some values | |
kubectl create secret generic db-secret --from-literal=DB_Host=sql01 | |
# multi container pod | |
kubectl run busybox --image=busybox --restart=Never --dry-run -o yaml -- bin/sh -c "sleep 3600; ls" > multi-container.yaml | |
# check logs for a container 1 and 2 | |
kubectl logs busybox -c busybox1 | |
kubectl logs busybox -c busybox2 | |
# Check the previous logs of the second container busybox2 if any | |
kubectl logs busybox -c busybox2 --previous | |
# Run command ls in the third container busybox3 of the above pod | |
kubectl exec busybox -c busybox3 -- ls | |
# Show metrics of the above pod containers and puts them into the file.log and verify | |
kubectl top pod busybox --containers > file.log | |
kubectl exec -it multi-cont-pod -c main-container -- sh cat /var/log/main.txt | |
# show labels | |
kubectl get pods --show-labels | |
# apply label | |
kubectl run nginx-dev1 --image=nginx --restart=Never --labels=env=dev | |
# Get the pods with label env=dev | |
kebectl get pods -l env=dev | |
# show labels which env in dev and prod | |
kubectl get pods -l 'env in (dev,prod)' | |
# update the label with overwrite | |
kubectl label po podone area=monteal --overwrite | |
# remove label named env | |
kubectl label pods podone env- | |
# show the labels for the nodes | |
kubectl get nodes --show-labels | |
# Annotate the pods with name=webapp | |
kubectl annnotate po podone name=webapp | |
# delete all the pods | |
kubectl delete po --all | |
# create a deployment with a name and replicas of 3 | |
kubectl create deployment webapp --image=nginx --replicas=3 | |
# scale deployment to have 20 replicas | |
kubectl scale deploy webapp --replicas=20 | |
# get the rollout status | |
kubectl rollout status deploy webapp | |
k expose deployment dep-name --name=service-name --port=x | |
# get the version numner | |
k explain pod --recursive | grep -i version | |
# force delete a pod | |
k delete pod podname --grace-period=0 --force | |
# scale RS | |
k scale rs new-replica-set --replicas=5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment