×


'kubectl get' Command - Explained with Examples

Kubernetes is an open-source platform that is the most portable for managing containerized workloads and services. It works as an automation tool by providing the services, support and tools that are widely available.

Whereas, Kubectl controls the Kubernetes Cluster as it is one of the key components of Kubernetes having the capability to manage the nodes in the cluster. Kubectl get command is capable of fetching the related data on the cluster about the Kubernetes resources.

Here at Ibmi Media, we shall look into the use of the 'Kubectl get' command with some examples.


Kubectl get commands

Some of the important kubectl get commands to fetch the data on the cluster about the Kubernetes resources are outlined below.


1. Kubectl get pod

To get the details about the pod of the container of the related kubernetes cluster, there is a command to do so.

To get the list of all the pods available on default namespace, run the below command:

$ kubectl get pod

But to get the details of the specific pod, you can enter the pod name as:

$ kubectl get pod <pod name>

Example:

$ kubectl get pod nginx-http-6cf5c9bf86-p5q2c

Here, the pod name is "nginx-http-6cf5c9bf86-p5q2c". It will display all the details regarding the specific pod.


2. Kubectl get deployment

To get the details about the deployments of the container of the related kubernetes cluster, this will help.

To get the list of all the deployments available on default namespace, run the below command:

$ kubectl get deployment

But to get the details of the specific deployment, you can enter the deployment name as:

$ kubectl get deployment <deployment name>

Example:

$ kubectl get deployment nginx-http

Here, the deployment name is "nginx-http". It will display all the details regarding the specific deployment.


3. Kubectl get service

To get the details about the service of the container of the related kubernetes cluster, this will help.

To get the list of all the services available on default namespace, run the below command:

$ kubectl get service

But to get the details of the specific service, you can enter the service name as:

$ kubectl get service <service name>

Example:

$ kubectl get service nginx-http-svc

Here, the service name is "nginx-http-svc". It will display all the details regarding the specific service.


4. Kubectl get ingress

To get the details about the ingress of the container of the related kubernetes cluster, this will help.

To get the list of all the ingress available on default namespace, run the below command:

$ kubectl get ingress

But to get the details of the specific ingress, you can enter the ingress name as:

$ kubectl get ingress <ingress name>

Example:

$ kubectl get ingress ingress-nginx

Here, the ingress name is "ingress-nginx". It will display all the details regarding the specific ingress.


5. Kubectl get configmap

To get the details about the configmap of the container of the related kubernetes cluster, this will do it.

To get the list of all the configmap available on default namespace, run the below command:

$ kubectl get configmap

But to get the details of the specific configmap, you can enter the config name as:

$ kubectl get configmap <configmap name>

Example:

$ kubectl get configmap nginx-http-cm

Here, the configmap name is "nginx-http-cm". It will display all the details regarding the specific configmap.


6. Kubectl get secrets

To get the details about the secrets of the container of the related kubernetes cluster, this is it.

To get the list of all the secrets available on default namespace, run the below command:

$ kubectl get secrets

But to get the details of the specific secrets, you can enter the secrets name as:

$ kubectl get secrets <secrets name>

Example:

$ kubectl get secrets default-token-xct8s

Here, the secret name is "default-token-xct8s". It will display all the details regarding the specific secrets.


7. Kubectl get namespace

To get the details about the namespace of the container of the related kubernetes cluster, the command is:

$ kubectl get namespace <namespace name>

Example:

$ kubectl get namespace

Here, we are using the default namespace. By running the command as "kubectl get namespace", we are listing all the available namespace.


[Need help in fixing Linux system issues ? We can help you. ]



Conclusion

This article covers kubectl Commands with Examples. In fact, Kubectl is a set of commands for controlling Kubernetes clusters. Every Kubernetes command has an API endpoint, and kubectl’s primary purpose is to carry out HTTP requests to the API.

While it is possible to issue HTTP requests yourself (e.g., using curl), kubectl is designed to make this process more comfortable and straightforward.


How to delete Resources using kubectl command ?

To remove resources from a file or stdin, use the kubectl delete command.

1. Remove a pod using the name and type listed in pod.yaml:

$ kubectl delete -f pod.yaml

2. Remove all pods and services with a specific label:

$ kubectl delete pods,services -l [label-key]=[label-value]

3. Remove all pods (including uninitialized pods):

$ kubectl delete pods --all