In kubectl you can specify optional flags for use with various commands.
alias – Set an alias for kubectl.
alias k=kubectlecho 'alias k=kubectl' >>~/.bashrc
-o=json – Output format in JSON.kubectl get pods -o=json-o=yaml – Output format in YAML.
kubectl get pods -o=yaml -o=wide
Output in the plain-text format with any additional information, and for pods, the node name is included.
kubectl get pods -o=wide
-n
– Alias for namespace.
kubectl get pods -n=<namespace_name>
-f – Filename, directory, or URL to files to use to create a resource.
kubectl create -f ./<file name>
-l – Filter using a specified label.
kubectl logs -l name=<label name>
-h – Help for kubectl.
kubectl -hConfiguration Files (Also referred to as Manifest or YAML Files)Configuration Files (Also referred to as Manifest or YAML Files.) – Kubernetes objects can be created, updated, and deleted by storing multiple object configuration files in a directory and using kubectl apply to recursively create and update those objects as needed. This method retains writes made to live objects without merging the changes back into the object configuration files. kubectl diff also gives you a preview of what changes apply will make.kubectl apply -f <configuration file>kubectl create -f <configuration file> – Create objects.kubectl create -f <configuration file directory> – Create objects in all manifest files in a directory.kubectl create -f <‘url’> – Create objects from a URL.kubectl delete -f <configuration file> – Delete an object.Read more about Kubectl Apply vs. Kubectl Create – What’s the Difference?.Cluster Management and ContextCluster management refers to querying information about the K8S cluster itself.kubectl cluster-info – Display endpoint information about the master and services in the cluster.kubectl version – Display the Kubernetes version running on the client and server.kubectl config view – Get the configuration of the cluster.kubectl config view -o jsonpath='{.users[*].name}' – Get a list of users.kubectl config current-context – Display the current context.kubectl config get-contexts – Display a list of contexts.kubectl config use-context <cluster name> – Set the default context.kubectl api-resources – List the API resources that are available.kubectl api-versions – List the API versions that are available.-A – List pods, services, daemonsets, deployments, replicasets, statefulsets, jobs, and CronJobs in all namespaces, not custom resource types. Note the alias for --all-namespaces is -Akubectl get all --all-namespaces