Exam Tips
Kubernetes Exam Tips.
Imperative Commands with dry-run
Use --dry-run=client
to generate the YAML file for the resource without actually creating it.
Format output with kubectl
For better readability, you can use this command kubectl [command] [TYPE] [NAME] -o <output_format>
to format the output.
Commonly used output formats are:
-o json
- Output a JSON formatted API object-o name
- Only display resource name-o wide
- Output in the plain-text format with any additional information-o yaml
- Output a YAML formatted API object
Edit a deployment
kubectl edit deployment <deployment-name>
will automatically delete the existing deployment and create a new one with the changes.
Edit a pod
When you edit an existing pod, there are some specifications you cannot edit. For example,
spec.containers[*].image
spec.initContainers[*].image
spec.activeDeadlineSeconds
spec.tolerations
If you use this command kubectl edit pod <pod-name>
, you cannot save the file after editing it, instead it will save the file with the changes in a temporary location.
So, in this case, we have multiple options to edit the pod:
-
Delete and apply the temporary file
-
Save existing pod, edit it, delete existing, and apply the edited file