CKAD Exam Certification Tips

  • Alias for kubectl is already set to k. So don`t need to create it again.

  • You need to generate yaml declarative file. So export "--dry-run=client -oyaml" part.
    Before:
    kubectl run pod --image=nginx --dry-run=client -oyaml
    After:
    export dr="--dry-run=client -oyaml"
    k run pod --image=nginx $dr

  • If you want to delete the pod or any other resource, don`t delete it using
    k delete pod. Because it will take some time. Instead, use
    k delete pod --grace-period=0 --force
    So it is good to create a variable for "--grace-period=0 --force" and use it for any other resource
    Eg:
    export now='--grace-period=0 --force'
    k delete pod $now

  • Learn all the imperative commands

    While you would be working mostly the declarative way - using definition files, imperative commands can help in getting one-time tasks done quickly, as well as generate a definition template easily. This would help save a considerable amount of time during your exams.

    Before we begin, familiarize yourself with the two options that can come in handy while working with the below commands:

    --dry-run: By default, as soon as the command is run, the resource will be created. If you simply want to test your command, use the --dry-run=client option. This will not create the resource. Instead, tell you whether the resource can be created and if your command is right.

    -o yaml: This will output the resource definition in YAML format on the screen.

    Use the above two in combination along with Linux output redirection to generate a resource definition file quickly, that you can then modify and create resources as required, instead of creating the files from scratch.

    kubectl run nginx --image=nginx --dry-run=client -o yaml > nginx-pod.yaml

    POD

    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

    Deployment

    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 -o yaml

    Generate Deployment with 4 Replicas

    kubectl create deployment nginx --image=nginx --replicas=4

    You can also scale deployment using the kubectl scale command.

    kubectl scale deployment nginx --replicas=4

    Another way to do this is to save the YAML definition to a file and modify

    kubectl create deployment nginx --image=nginx--dry-run=client -o yaml > nginx-deployment.yaml

    You can then update the YAML file with the replicas or any other field before creating the deployment.

    Service

    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

    (This will automatically use the pod's labels as selectors)

    Or

    kubectl create service clusterip redis --tcp=6379:6379 --dry-run=client -o yaml (This will not use the pods' labels as selectors; instead it will assume selectors as app=redis. You cannot pass in selectors as an option. So it does not work well if your pod has a different label set. So generate the file and modify the selectors before creating the service)

    Services and Network

    kubectl expose pod my-pod --type=NodePort --port=80 --target-port=8080 kubectl create ingress my-ingress --rule=/path=service-name:port

    kubectl port-forward my-pod 8080:80

    ConfigMaps and Secrets

    kubectl create configmap my-config --from-literal=key1=value1 --from-literal=key2=value2

    kubectl create secret generic my-secret --from-literal=username=user --from-literal=password=pass

    Jobs and CronJobs

    kubectl run my-job --image=my-image --restart=OnFailure

    kubectl create cronjob my-cronjob --schedule="*/1 " --image=my-image

    Resource Quotas and Limits

    kubectl create quota my-quota --hard=pods=2,services=5

    kubectl create limitrange my-limitrange --limits=cpu=200m,memory=100Mi