Kubernetes – Getting ready for CKAD Certification

Although you can refer to the official Kubernetes during the exam, you need to be very fast at completing the tasks.

So it´s important to use aliases and shortcuts, take advantage of the documentation in the CLI (like “kubectl explain” or “–help”) and understand how to update resources.

CREATE ALIASES AND SHORTCUTS

The “k” alias for “kubectl” is provided. But to spare time, once you are logged in the exam shell, you might additionally need to define other things, like the context switching:

$ alias kn='kubectl config set-context --current --namespace 

$ export now=”--force --grace-period 0”

$ export do=“--dry-run=client -o yaml”

This way, creating a yaml for a pod file becomes a lot easier:

$ k run pod1 --image=httpd:2.4.31-alpine --labels="test=true,tenancy=test" --env tempdir=/tmp $do > pod.yaml

This allows you to edit the file before creating the objects with “k create -f” or “k apply -f“:

$ k create -f pod1.yaml

USE THE CLI DOCS RATHER THAN WEB PAGES

For example
$ kubectl explain pods.spec.tolerations

UPDATE DEPLOYMENTS QUICKLY

After creating a deployment with replicas:

$ kubectl create deploy httpd-frontend --image=httpd:2.4-alpine

you can update the number of replica live :

$ k scale --replicas 6 deployment httpd-frontend

And also, for example, add resources limits:

$ k set resources deploy httpd-frontend --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=256Mi

You can add new labels, like:

$ k label deploy httpd-frontend tenancy=prod

Or ovewrite an existing one:

$ k label deploy httpd-frontend app=frontend --overwrite

ADD environment variables:

$ kubectl set env deployment/registry STORAGE_DIR=/local

Or even directly from a config map or a secret
$ kubectl set env deployment nginx --from=configmap/vars --keys="var1,var2"
$ kubectl set env deployment nginx --from=secret/passwords --keys="pass1

Let´s try for example:

$ k set env deploy httpd-frontend --env var3=344343

Once you have set the environment variable, the pods are terminated and recreated.

So you need to pick a new one to check if the environmente varialbe is there:

if you update the image:

$ kubectl set image deploy httpd-frontend httpd=httpd:2.6-alpine

Afterwards you can add an annotation to the current deployment, to see the information in the rollout history:

$ kubectl annotate deploy httpd-frontend kubernetes.io/change-cause='update image'

EXPOSING A DEPLOYMENT OR POD (SERVICE CREATION)

Services can also be created with commands, like:

$ kubectl expose deploy redis -n marketing --type=NodePort --port=6379 --name=msg-svc

$ kubectl expose pod redis --port=6379 --target-port=6379 --name=redis-service

this will make Kubernetes create a service for you deployment.

You can also use “create service”:

$ kubectl create service clusterip my-cs --clusterip="None"

PASSING A COMMAND TO A NEW JOB

$ k create job njob –-image=busybox:1.31.0 $do > job.yaml –- sh -c “sleep 2 && echo done”

POD CPU USAGE

You will be asked to check which pods is consuming the most CPU. You can check it out with “top”:

$ k top <podname>

CREATE A VOLUME CONFIGURATION IN A POD

Although deprecated, if you only need a pod with volumes, using the “-o yaml” option will add one for you, that you can later edit.

k run nginx2 --image=nginx -o yaml > lab5.yaml

Of course there´s a lot of lines to clean up, but if you are fast with vim you can make it.

this will run a pod, but you can delete it and keep the file for creating what you need.

RUN NEW PODS WITH CONFIGURATION ELEMENTS

You add other stuff in your configuratio in the CLI directly, like:

  • labels
  • environment variables
  • command for your pod
  • service account

k run mypod --image=busybox --labels="tier=msg,review=none" --env VAR1=hello --env VAR2=world –serviceaccount=mysa -o yaml > p.yaml --command -- sh -c "while true; do date; sleep 2; done"

Then you just need to delete the pod “mypod”, edit the yaml file (deleting the “managedFields” sections) and create the pod you need.

This is much better than copying and pasting codes, as you don´t have indentation issues. And you can quickly find the command options at:

https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

On the right side of the docs you always have examples:

CREATE VS RUN

You can use “kubectl run” to create pods.

$ kubectl run alpaca-prod --image=gcr.io/kuar-demo/kuard-amd64:blue --labels="ver=1,app=alpaca,env=prod"

But if you want to create a deployment you can´t use run. You will need to use “kubectl create”:

$ kubectl create deploy httpd-frontend --image=httpd:2.4-alpine

MAKE SURE THINGS WORK!

Check things are running with “kubectl get”, or describe:

$ K describe po messaging | grep -C 5 -I labels

Pipe commands with grep to avoid scrolling too much. you won´t have time!

Access pods to run commands in the bash:
$ kubectl exec -it sidecar-pod -c sidecar– /bin/sh

And curl service endpoints!

JOBS & CRONJOBS

To create a job imperatively, pass the command at the end:

$ K create job neb-new-job –-image=busybox:1.31.0 $do > /opt/course/3/job.yaml –- sh -c “sleep 2 && echo done”

To create a cronjob, you generally need to pass the schedule parameter

$ kubectl create cronjob dice –-image=kodecloud/throw dice –-schedule=”*/1 * * * *”

You can as well create a job out of a cronjob:

$ kubectl create job test-job --from=cronjob/a-cronjob

TEST YOUR SERVICES

You should be able to curl your service:

A temporary pod with the nginx:alpine immage running curl would be helpful:

$ kubectl run tmp --restart=Never --rm -i --image=nginx:alpine -- curl -m 5 manager-api-svc:4444

If you can´t curl this way, probably the service is malconfigured..and endpoint missing.

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
Cookies settings
Accept
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Privacy Policy

What information do we collect?

We collect information from you when you register on our site or place an order. When ordering or registering on our site, as appropriate, you may be asked to enter your: name, e-mail address or mailing address.

What do we use your information for?

Any of the information we collect from you may be used in one of the following ways: To personalize your experience (your information helps us to better respond to your individual needs) To improve our website (we continually strive to improve our website offerings based on the information and feedback we receive from you) To improve customer service (your information helps us to more effectively respond to your customer service requests and support needs) To process transactions Your information, whether public or private, will not be sold, exchanged, transferred, or given to any other company for any reason whatsoever, without your consent, other than for the express purpose of delivering the purchased product or service requested. To administer a contest, promotion, survey or other site feature To send periodic emails The email address you provide for order processing, will only be used to send you information and updates pertaining to your order.

How do we protect your information?

We implement a variety of security measures to maintain the safety of your personal information when you place an order or enter, submit, or access your personal information. We offer the use of a secure server. All supplied sensitive/credit information is transmitted via Secure Socket Layer (SSL) technology and then encrypted into our Payment gateway providers database only to be accessible by those authorized with special access rights to such systems, and are required to?keep the information confidential. After a transaction, your private information (credit cards, social security numbers, financials, etc.) will not be kept on file for more than 60 days.

Do we use cookies?

Yes (Cookies are small files that a site or its service provider transfers to your computers hard drive through your Web browser (if you allow) that enables the sites or service providers systems to recognize your browser and capture and remember certain information We use cookies to help us remember and process the items in your shopping cart, understand and save your preferences for future visits, keep track of advertisements and compile aggregate data about site traffic and site interaction so that we can offer better site experiences and tools in the future. We may contract with third-party service providers to assist us in better understanding our site visitors. These service providers are not permitted to use the information collected on our behalf except to help us conduct and improve our business. If you prefer, you can choose to have your computer warn you each time a cookie is being sent, or you can choose to turn off all cookies via your browser settings. Like most websites, if you turn your cookies off, some of our services may not function properly. However, you can still place orders by contacting customer service. Google Analytics We use Google Analytics on our sites for anonymous reporting of site usage and for advertising on the site. If you would like to opt-out of Google Analytics monitoring your behaviour on our sites please use this link (https://tools.google.com/dlpage/gaoptout/)

Do we disclose any information to outside parties?

We do not sell, trade, or otherwise transfer to outside parties your personally identifiable information. This does not include trusted third parties who assist us in operating our website, conducting our business, or servicing you, so long as those parties agree to keep this information confidential. We may also release your information when we believe release is appropriate to comply with the law, enforce our site policies, or protect ours or others rights, property, or safety. However, non-personally identifiable visitor information may be provided to other parties for marketing, advertising, or other uses.

Registration

The minimum information we need to register you is your name, email address and a password. We will ask you more questions for different services, including sales promotions. Unless we say otherwise, you have to answer all the registration questions. We may also ask some other, voluntary questions during registration for certain services (for example, professional networks) so we can gain a clearer understanding of who you are. This also allows us to personalise services for you. To assist us in our marketing, in addition to the data that you provide to us if you register, we may also obtain data from trusted third parties to help us understand what you might be interested in. This ‘profiling’ information is produced from a variety of sources, including publicly available data (such as the electoral roll) or from sources such as surveys and polls where you have given your permission for your data to be shared. You can choose not to have such data shared with the Guardian from these sources by logging into your account and changing the settings in the privacy section. After you have registered, and with your permission, we may send you emails we think may interest you. Newsletters may be personalised based on what you have been reading on theguardian.com. At any time you can decide not to receive these emails and will be able to ‘unsubscribe’. Logging in using social networking credentials If you log-in to our sites using a Facebook log-in, you are granting permission to Facebook to share your user details with us. This will include your name, email address, date of birth and location which will then be used to form a Guardian identity. You can also use your picture from Facebook as part of your profile. This will also allow us and Facebook to share your, networks, user ID and any other information you choose to share according to your Facebook account settings. If you remove the Guardian app from your Facebook settings, we will no longer have access to this information. If you log-in to our sites using a Google log-in, you grant permission to Google to share your user details with us. This will include your name, email address, date of birth, sex and location which we will then use to form a Guardian identity. You may use your picture from Google as part of your profile. This also allows us to share your networks, user ID and any other information you choose to share according to your Google account settings. If you remove the Guardian from your Google settings, we will no longer have access to this information. If you log-in to our sites using a twitter log-in, we receive your avatar (the small picture that appears next to your tweets) and twitter username.

Children’s Online Privacy Protection Act Compliance

We are in compliance with the requirements of COPPA (Childrens Online Privacy Protection Act), we do not collect any information from anyone under 13 years of age. Our website, products and services are all directed to people who are at least 13 years old or older.

Updating your personal information

We offer a ‘My details’ page (also known as Dashboard), where you can update your personal information at any time, and change your marketing preferences. You can get to this page from most pages on the site – simply click on the ‘My details’ link at the top of the screen when you are signed in.

Online Privacy Policy Only

This online privacy policy applies only to information collected through our website and not to information collected offline.

Your Consent

By using our site, you consent to our privacy policy.

Changes to our Privacy Policy

If we decide to change our privacy policy, we will post those changes on this page.
Save settings
Cookies settings