In case of editing existing Pod, what is the best practice / in CKA exam we shou . . .

K8s_Member:
In case of editing existing Pod, what is the best practice / in CKA exam we should use it (Option 1 or 2)?

  1. k edit pod [pod_name] , then k replace --force -f ...
  2. k get pod [pod_name] -o yaml > newpod.yaml

Alistair Mackay:
You can use whichever method works for you - which one you find quickest. The exam is scored on the end result, not what you did to get there.

Bear in mind that if you edit a pod with k edit , unless you are only changing the image , it is going to tell you that you cannot edit immutable fields, and then you have to muck around with files that vi saves in /tmp. All other resources work fine with k edit

You usually want to delete a running pod with k delete pod ... --grace-period 0 --force to make it die immediately, else you might be waiting up to 30 seconds due to grace period, especially for pods running sleep

K8s_Member:
So I should use option 2, right? 3 steps

  1. k get pod [pod_name] -o yaml > newpod.yaml #To get current state
  2. k delete pod ... --grace-period 0 --force #To delete running pod
  3. k apply -f newpod.yaml#Create the new pod.

Alistair Mackay:
Yup. Taking into account grace period it can be quicker.

You can create an alias for the delete to make it faster

At beginning of exam

vi .bashrc

Go to end of file
Add the following line

alias kdp='kubectl delete pod --grace-period 0 --force'

Save it.
Close the terminal app and open it again.

Then you can type e.g.

kdp busybox

Practice on kodekloud lab simply by creating the alias at the command prompt (since we don’t close terminal there)

K8s_Member:
I meant safe perpective.

Alistair Mackay:
Safe in what way?

Alistair Mackay:
Exam marking script is only concerned with the pod being correct at the end

K8s_Member:
When I practice test, I have mistake to edit wrong
As a result, running pod is deleted, new pod from /tmp.. file can not create.

So I think about “best practice” to avoid lose the original state.

Alistair Mackay:
If you want to preserve the original state, then get the pod to a yaml file and make a second copy of it. Then edit only one copy

K8s_Member:
Thanks for your tips alias kdp='kubectl delete pod --grace-period 0 --force '

Alistair Mackay:
You can make up other aliases for commands you might use frequently

alias 'kgp=kubectl get pods'
alias 'kgd=kubectl get deployments'

etc.
gives you e.g.

kgd

kgp -n another-namespace a-pod

Alistair Mackay:
I discuss things that you can do when the exam starts here:
https://github.com/fireflycons/tips-for-CKA-CKAD-CKS#exam-environment-configuration

K8s_Member:
Yup, I’ve already had theses alias for myself

------------Alias
alias kgp='k get po'
alias kgs='k get svc'
alias kgn='k get node'
alias kgd='k get deploy'
alias kn='k config set-context --current --namespace '
alias ka='k apply -f '
alias kr='k run --dry-run=client -oyaml --image '

K8s_Member:
The interesting is your trick --grace-period 0 --force is new for me. Thanks sir.

Alistair Mackay:
Important thing to remember in exam is to add your aliases to .bashrc because you can (and should) open multiple terminal windows

K8s_Member:
I try edit .bashrc
image.png

K8s_Member:
but it’s not working, why?
image.png

K8s_Member:
Oh i see "After saving this, close the terminal and open a new one. Your saved settings will now be active."

K8s_Member:
open new terminal is working now
image.png

Alistair Mackay:
Because you have not reloaded bashrc.
I also said that we don’t close and reopen the terminal in kodekloud labs.
If you put the stuff into .bashrc, open another terminal tab, and then it will be loaded.
image.png