kubectl explain.
alias k=kubectl source <(kubectl completion bash) complete -F __start_kubectl k export do='--dry-run=client -o yaml'
k run nginx \ --image=nginx \ $do > pod.yaml
k create deployment web \ --image=nginx \ $do > deploy.yaml
k expose deployment web \ --port=80 \ --target-port=80 \ $do > svc.yaml
kubectl explain podShows:
apiVersion kind metadata spec statusDrill deeper:
kubectl explain pod.specThen:
kubectl explain pod.spec.containersThen:
kubectl explain pod.spec.containers.image
kubectl explain networkpolicy.spec
kubectl explain networkpolicy.spec.ingress
kubectl explain networkpolicy.spec.ingress.from
kubectl explain networkpolicy.spec.ingress.portsUseful for exam tasks like:
kubectl explain pvc.spec
kubectl explain pvc.spec.resources
kubectl explain pvc.spec.resources.requestsUse when creating:
kubectl explain pod.spec.tolerationsShows:
key operator value effect tolerationSecondsUseful for:
kubectl explain ingress.spec.rules
kubectl explain ingress.spec.rules.http
kubectl explain ingress.spec.rules.http.paths
kubectl explain ingress.spec.rules.http.paths.backendUseful when you forget backend/service syntax.
kubectl explain pod --recursiveExample output:
KIND: Pod
apiVersion
kind
metadata
name
namespace
spec
containers
image
ports
Quick way to see an entire object structure.
kubectl get pods kubectl describe podMemorize these four commands.kubectl logs kubectl exec -it -- sh
1. Generate YAML kubectl create ... --dry-run=client -o yaml 2. Edit YAML vi file.yaml 3. Discover fields kubectl explain ... 4. Apply kubectl apply -f file.yaml
You do not need to memorize every YAML field. You only need to know how to quickly find it.