This guide provides essential commands to check the status of various Kubernetes objects, including Pods, Nodes, Services, ConfigMaps, Secrets, StatefulSets, and Deployments. These commands will help you monitor the health and performance of your Kubernetes cluster.
Checking the status of Kubernetes objects allows you to verify that your applications are running as intended. It helps in identifying and troubleshooting issues, such as failed deployments, unresponsive services, or pods that are not in a ready state. Regular monitoring of these objects is critical for maintaining the health and performance of your Kubernetes cluster.
Checking Pod Status
What is a Pod?
A Pod is the smallest deployable unit in Kubernetes, representing a group of one or more application containers with shared storage/network resources and a specification for how to run the containers.
Command to Check Pod Status
kubectl get pods
Example Output:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nextgen-gw-0 0/3 Running 0 5s
- READY: Indicates how many containers in the pod are ready.
- STATUS: Shows the current status of the pod (e.g., Running, Pending, Failed).
- RESTARTS: The number of times the containers in the pod have restarted.
- AGE: How long the pod has been running.
Checking Node Status
What is a Node?
A Node is a physical or virtual machine in a Kubernetes cluster that runs one or more pods. Each Node is managed by the Kubernetes control plane, which automatically handles scheduling the pods across the Nodes.
Command to Check Node Status
kubectl get nodes
Example Output:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready <none> 5d20h v1.18.2
- STATUS: Should be Ready to indicate that the Node is functioning properly.
- ROLES: Shows the roles assigned to the Node (e.g., control plane, worker).
- AGE: Indicates how long the Node has been part of the cluster.
- VERSION: Displays the Kubernetes version running on the Node.
Checking Kubernetes Services
What is a Service?
A Service in Kubernetes is an abstraction that defines a logical set of Pods and a policy by which to access them. Services enable the routing of traffic to the appropriate pods across the cluster.
Command to Check Service Status
kubectl get svc
Example Output:
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d
- TYPE: Specifies how the service is exposed (e.g., ClusterIP, NodePort, LoadBalancer).
- CLUSTER-IP: The internal IP address of the service.
- EXTERNAL-IP: The external IP address (if the service is exposed outside the cluster).
- PORT(S): The port(s) the service is exposed on.
- AGE: Indicates how long the service has been running.
Checking ConfigMaps
What is a ConfigMaps?
A ConfigMap is used to store non-confidential configuration data in key-value pairs. ConfigMaps allow you to decouple environment-specific configurations from container images, making applications more portable.
Command to Check ConfigMaps Status
kubectl get cm
Example Output:
$ kubectl get cm
NAME DATA AGE
app-config 3 7d
- DATA: Indicates the number of key-value pairs in the ConfigMap.
- AGE: Shows how long the ConfigMap has been in the cluster.
Checking Secrets
What is a Secrets?
A Secret is used to store and manage sensitive information, such as passwords, tokens, or keys. Secrets are similar to ConfigMaps, but they are intended to hold confidential data.
Command to Check Secrets Status
kubectl get secrets
Example Output:
$ kubectl get secrets
NAME TYPE DATA AGE
default-token-abc123 kubernetes.io/service-account-token 3 7d
- TYPE: Indicates the type of secret (e.g., Opaque, kubernetes.io/service-account-token).
- DATA: The number of data entries (key-value pairs) in the secret.
- AGE: Shows how long the secret has been in the cluster.
Checking StatefulSets
What is a StatefulSets?
A StatefulSet is a Kubernetes controller that manages the deployment and scaling of a set of Pods with unique, persistent identities. StatefulSets are used for applications that require stable storage and network identities, such as databases.
Command to Check StatefulSets Status
kubectl get statefulset
Example Output:
$ kubectl get statefulset
NAME READY AGE
web 1/1 7d
- READY: Indicates how many replicas are ready.
- AGE: Shows how long the StatefulSet has been running.