Kubectl list-clusters and commands to know | Padok (2024)

Posted on 21 October 2019, updated on 25 October 2023.

Are you confident in your use of Kubectl? If not, this article can help you. Kubernetes environment brings together a lot of resources and technologies. Having a solid foundation of fundamental commands for creating, deleting and monitoring these resources could save you a lot of time.

A bit of context: Kubectl?

"Kubectl is a command-line interface that lets you run commands on Kubernetes clusters." This is how we will be able to perform various operations on our cluster and kubernetes objects. Here is a cheat sheet of most usefull kubectl commands.

Kubectl depends on a kubeconfig file. This is a configuration file for access to one or more clusters. We will talk about context, to know which cluster is configured our Kubectl command, we can use:

  • Kubectl config current-context

If we want to list all our kubeconfig contexts, we run:

  • Kubectl config get-contexts

Or if we want to change clusters in our config, we can use:

Kubectl monitoring commands

  • Kubectl get pods

This command lists pods on the Kubernetes cluster. This command works for all types of Kubernetes resources: pods, services, deployments, cronjobs, events, ingresses, etc. We can also add parameters:

--all-namespaces: List all resources of all namespaces.

-o wide: List all resources with more details.

  • Kubectl describe pod

The describe command gives a verbose display of the pod unlike the get and basic display. This allows having the events, useful when a pod does not start.

e.g. Kubectl describe pods my-pod.

  • Kubectl logs [-f] POD [-c CONTAINER]

This command displays the logs of your POD. We can add the -c container option when we want to display the logs of a multi-container pod. The -f command displays the output of the logs continuously (stream).

Example: Kubectl logs -f my_pod -c my_app

-> Stream the logs of the container my_app on the my_podpod.

  • Kubectl top pod POD_NAME --containers

Displays the metrics for a given pod and its containers within a Kubernetes cluster.

  • Kubectl attach POD_NAME -c CONTAINER_NAME

Attach to a process that is already running inside an existing container.

  • Kubectl exec POD_NAME -it -- COMMAND_NAME

Execute a command in a running container.

  • Kubectl edit pod POD_NAME

Edit the pod configuration and apply changes on save.

Kubectl Create / Delete Commands

  • Kubectl create -f FILE

Create one or more resources from your yaml files or folder.

  • Kubectl apply -f FILE

Applies a configuration change to a resource from your yaml files.

  • Kubectl delete (-f FILE | TYPE [PREFIX_NAME | NAME])

Deletes one or more Kubernetes resources from a configuration file or directly from resource names.

e.g. Kubectl delete my_pod (destroy the pod on the cluster named my_pod)

  • Kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT

Lets you expose a local port to the port of a POD that is running on the Kubernetes cluster. Useful to debug.

e.g. Kubectl port-forward my_pod 80:3000 (exposes the port 3000 of the pod my_pod on our local port 80)

  • Kubectl run NAME --image=image [--env=”key=value”] [--port=port] [--replicas=replicas]

Run a resource in the Kubernetes cluster.

e.g. Kubectl run -i --tty busybox --image=busybox -- sh

-> Run a pod as an interactive shell

Here are the basic commands of Kubectl for managing Kubernetes configuration and resources. Do not hesitate to contact us if you have any questions or want us to add some commands to the article. I also advise you to read this article about Kubernetes' "tips and tricks" to improve your productivity with Kubernetes. To go further on the level of containerization, I invite you to consult this article concerning the commands of docker and docker-compose to know.

Kubectl list-clusters and commands to know | Padok (2024)

FAQs

How do I get detailed information of a Kubernetes cluster? ›

To get detailed information to further debug and diagnose cluster problem, use kubectl cluster-info dump. To get only the health status for your node use, kubectl get componentstatus or kubectl get cs.

How to check which cluster kubectl? ›

Kubectl depends on a kubeconfig file. This is a configuration file for access to one or more clusters. We will talk about context, to know which cluster is configured our Kubectl command, we can use: Kubectl config current-context.

How do I view cluster events using kubectl command? ›

Accessing Kubernetes Events

Running the kubectl describe command on specific cluster resources will list the events for that resource. A more generic way of doing this is by running the kubectl get events command, which lists the specific resources' events or the entire cluster.

How do I view cluster configuration in Kubernetes? ›

You can use the kubectl config command to view your current Kubernetes configurations. This can be done using the kubectl config view command. This command will output the entire kubeconfig file, displaying all your clusters, contexts, and users.

Which of the following command is used to get details information of a Kubernetes cluster? ›

If you need more detailed information about a specific pod, you can use the kubectl describe pod command. This command will provide you with detailed information about the specified pod, including the pod's containers, IP address, labels, annotations, and more.

What is the command to list all the available objects in your Kubernetes cluster? ›

The most basic command for viewing Kubernetes objects via kubectl is get . If you run kubectl get <resource-name> you will get a listing of all resources in the current namespace.

How to check cluster info? ›

Display addresses of the control plane and services with label kubernetes.io/cluster-service=true. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

What is the command to check cluster status? ›

Checking status of the cluster:

clustat -m -> Display status of and exit. clustat -s -> Display status of and exit. clustat -l -> Use long format for services. cman_tool status -> Show local record of cluster status.

What is the right command to check the cluster status? ›

To see the overall status of the cluster from the command-line, use either of these commands: Display Cluster Information (DSPCLUINF) command. Display Cluster Resource Group Information (DSPCRGINF) command. Work with Cluster (WRKCLU) command.

How do I check my Kubernetes cluster performance? ›

You can examine application performance in a Kubernetes cluster by examining the containers, pods, services, and the characteristics of the overall cluster. Kubernetes provides detailed information about an application's resource usage at each of these levels.

What is the command to get the cluster name in Kubernetes? ›

kubectl command-line tool: You can use the following command to get the name of the current context, which also includes the name of the cluster: “ kubectl config current-context

How do I check my EKS cluster? ›

Verify EKS Anywhere cluster status
  1. kubectl get nodes.
  2. kubectl get machines -A.
  3. kubectl get pods -A.
  4. kubectl get pod -A -l control-plane=controller-manager.
  5. export CLUSTER_NAME=mgmt export KUBECONFIG=${CLUSTER_NAME}/${CLUSTER_NAME}-eks-a-cluster.kubeconfig.

What is the command to check cluster nodes in Linux? ›

You can get detailed information on the nodes in the cluster.
  1. The following command lists all nodes: $ oc get nodes. The following example is a cluster with healthy nodes: $ oc get nodes. ...
  2. The following command lists information about a single node: $ oc get node <node> For example: $ oc get node node1.example.com.

How to do cluster configuration? ›

Steps for configuring a cluster
  1. Step 1: Configure a basic cluster, or a cluster with an application. ...
  2. Step 2: Configure additional topology components. ...
  3. Step 3: Configure the cluster resources. ...
  4. Step 4: Configure the resource groups. ...
  5. Step 5: Put the resources to be managed together into their respective resource groups.

Which command is used to check all nodes in the cluster in Kubernetes? ›

kubectl get nodes is a powerful command that provides essential information about the nodes in your Kubernetes cluster. When you execute this command, it communicates with the Kubernetes API server, retrieving the necessary information from the cluster's control plane.

Which file provides the details to access a cluster? ›

The kubeconfig file (by default named config and stored in the $HOME/. kube directory) provides the necessary details to access the cluster. Having set up the kubeconfig file, you can start using kubectl to manage the cluster.

What tool can be used to view information about a GKE cluster? ›

The Google Cloud console offers useful dashboards for your project's GKE clusters and their resources. You can use these dashboards to view, inspect, manage, and delete resources in your clusters.

How do I get the health of my Kubernetes cluster? ›

Check Cluster Health
  1. Run the command kubectl describe cluster . If the status is ready, it means that both the cluster infrastructure and the cluster control plane are ready. ...
  2. If the cluster is not ready, run the following command to determine what is wrong with the cluster infrastructure: kubectl describe wcpcluster.
Oct 20, 2021

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 5925

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.