Here are some commonly used kubectl flags:
-
-for--filename: Specifies the file or directory containing the resource definitions to apply.kubectl apply -f my-deployment.yaml -
-oor--output: Defines the output format. Common formats includejson,yaml,wide, andname.kubectl get pods -o json -
--namespace: Similar to-n, it specifies the namespace for the command.kubectl get services --namespace=my-namespace -
--kubeconfig: Specifies the path to the kubeconfig file to use for the command.kubectl get pods --kubeconfig=/path/to/kubeconfig -
--context: Specifies the context to use from the kubeconfig file.kubectl config use-context my-context -
--dry-run: Simulates the command without making any changes. Useful for testing.kubectl apply -f my-deployment.yaml --dry-run=client -
-lor--label-selector: Filters resources based on labels.kubectl get pods -l app=my-app -
--all-namespaces: Lists resources across all namespaces.kubectl get pods --all-namespaces
These flags can be combined to tailor the kubectl command to your specific needs.
