Kubectl is a command line that interfaces with Kubernetes environments. kubectl is primarily used to communicate with Kubernetes API servers to create, update, delete workloads within Kubernetes.
Refer to this URL on how to install kubectl.
To access your Kubernetes cluster, kubectl uses a configuration file. The default kubectl configuration file is located at ~/.kube/config and is referred to as the kubeconfig file.
kubeconfig files combine information about clusters, users, namespaces, and authentication mechanisms. The kubectl command applies these files to find the information it requires to pick a cluster and communicate with it.
Use this command to print the client and server versions.
Use this command to print information about the control plane and add-ons.
4. kubectl api-versions and kubectl api-resources print information about the available Kubernetes APIs.
Use get to pull a list of resources you have currently on your cluster. The types of resources you can get include:
Each of these provides details about the available resources in the cluster. Without a namespace flag, the command will always show the information of the default.
-o name : Print only the resource name and nothing else.
-o wide : Output in the plain-text format with any additional information.
-o yaml : Output a YAML formatted API object.
-o json : Output a JSON formatted API object
After selecting the appropriate context for the cluster, we can check on the status of the core master components using the get componentstatuses (abbreviated to get cs) command
kubectl get cs
kubectl get pods or kubectl get po
kubectl get pods -o wide
kubectl get pod --all-namespaces
Instead of --all-namespaces, you can use shorter version -A
5.d. PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.
kubectl get pv
5.e. PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources.
kubectl get pvc
kubectl get nodes OR kubectl get no
kubectl get ns or kubectl get namespaces