This Document was created at 03/2023
- Kubernetes version:
1.26
2 hours
15-20
questions- Pass mark of
66%
Webcam
andmicrophone
- Remotely proctored
- Chrome browser plus an extension
- Steady internet, preferably 5MB up/down
Please check more details at CNCF Repo
Workloads & Scheduling (15%)
Services & Networking (20%)
Storage (10%)
Troubleshooting (30%)
For convenience, abbreviate kubectl to k After this section,
vi ~/.bashrc
# write down at end of bashrc
# Auto Completion
kubectl completion bash
kubeadm completion bash
# Alias Setting
alias kc="kubectl create"
export do="--dry-run=client -o yaml" # Create the YAML tamplate (usage: $do)
# Save and Quit
exec $SHELL # Reload shell(Must CAPITAL)
# usage example
kc deploymentmy my-dep --image=nginx --replicas=3
kc deployment --image=nginx nginx $do
k run --image=busybox $do -- "/bin/sh" "-c" "sleep 36000"
pods
: podeployments
: deployservices
: svcreplicasets
: rsreplicationcontollers
: rcconfigmaps
: cmnamespaces
: nsnodes
: nopersistentvolumeclaims
: pvcpersistentvolumes
: pvresourcequotas
: quotaserviceaccounts
: sadaemonsets
: dscronjobs
: cjingresses
: ingstorageclasses
: sc
# Check the status of kubelet
sudo systemctl status kubelet
# Check correct context
k config get-contexts
k config set-context ${Context_Name} # if you want to change context
# Check the status of System Pod
k logs -n kube-system ${System_Pod_Name}
# Display addresses of the master and services
k cluster-info [dump] # dump option is for more detail
# List all resources in all namespaces, with more details
k get all -A -o wide
# Show related events, metrics for troubleshooting
k describe pods ${Pod_Id}
k top node my-node
k explain deployment --recursive
# create a deployment
k create deploy nginx --image=nginx
# create a service & ingress
k create svc clusterip my-service --tcp=80:80
k create ingress ${Name} --tcp=80:80
# create a secret & configmap
k create secret generic my-secret --from-file ${File_Name}
k create configmap my-config --from-literal=special.how=very
if you want to create a resource from the yaml file,
you can use the following command (Don't memorize yaml file)
# from existing resource
k get pod ${Pod_Id} -o yaml > pod.yaml
# from scratch
k create deploy nginx --image=nginx > deploy.yaml
# if you have set alias, you can use $do
k create deploy nginx --image=nginx $do > deploy.yaml
# apply changes to resource (partial change)
k apply -f ${File_Name}
# replaces a resource with a new configuration file.
# old resource will be removed and new one created.
k replace -f ${File_Name}
# edit in user’s shell.
k edit ${Resource_Type} ${Resource_Name}
# patch a resource with new property values.
k patch ${Resource_Type} ${Resource_Name} -p '{"property_name":"new_value"}'
# updates the container image in a deployment.
k set image deployment ${Deployment_Name} ${New_Image}=${Image_Url}
# restarts a rollout of a Kubernetes resource
k rollout restart deployment ${Deployment_Name}
# Scale a deployment
k scale deploy my-deployment --replicas=5
# Delete a pod
k delete pod ${podId}
# Force delete a pod
k delete pod ${podId} --force --grace-period=0
# Delete all specified resources in current namespace
k delete pod -n test --all
Only one thing to remember is that the Role and ClusterRole are the same,
but the Role is in the namespace, and the ClusterRole is not in the namespace.
k create [role, clusterrole] dev-role \
-n default \ # ClusterRole has no namespace
--verb=get,list,watch,update \
--resource=pods \
--resource-name=test-pod
k create rolebinding dev-binding \
-n default \ # ClusterRoleBinding has no namespace
--role=dev-role \
--clusterrole=dev-clusterrole \
--serviceaccount=default:test-sa
# Count the number of pods in a namespace
k get pod -n my-namespace | wc -l
# Check authentication
k auth can-i create deployments -n default --as guest
https://github.com/leandrocostam/cka-preparation-guide
https://github.com/ismet55555/Certified-Kubernetes-Administrator-Notes
https://github.com/arush-sal/cka-practice-environment
https://github.com/kodekloudhub/certified-kubernetes-administrator-course