When we switch to current context as cluster1 then is it necessary to go with each time adding additional command --context cluster1 which is time consuming. I can see this is being suggested and feedback after exam finished. Let me know if I am wrong/my understanding. It will help to avoid making mistake while in final exam.
student-node ~ ➜ kubectl --context cluster1 create serviceaccount <
student-node ~ ➜ kubectl --context cluster1 create clusterrole --resource=deployments --verb=get
You don’t need to use --context
on every command.
You can simply set the default context, the command to do this is provided with every question (in the real exam too), and can be copy-pasted e.g.
kubectl config use-context cluster1
then all subsequent commands will execute on cluster1 until you do another use-context
, or explicitly provide a --context
When you should always use --context
is for questions that say make a script that contains a kubectl command to do something or other.
That way when the exam is graded at the end it does not matter what context you left the environment in with a use-context
Also remember to use k
alias and completion and not type every option fully.
If you were to type
k --co
then hit TAB key, it will fill in the rest of --context
for you. Works for all the command flags, and also for resources
k get po
then TAB (or first one or two letters of name if you know them) and it will present you with matching pod names if there are any pods in the namespace.
k get po n<TAB>
might fill in to nginx
if that’s running
etc.
Thanks Alistair for the explanation.