☸ Kubernetes troubleshooting Commands:
kubectl get pods
- This command will show the status of all pods in the current namespace.
kubectl describe pod <pod-name>
- This command will give detailed information about the specified pod, including its current status, events, and container statuses.
kubectl logs <pod-name> <container-name>
- This command will print the logs of the specified container within the specified pod.
kubectl exec -it <pod-name> <container-name> /bin/bash
- This command will open a shell inside the specified container within the specified pod, which can be useful for debugging.
kubectl get events
- This command will show the recent events that have occurred in the cluster, which can help identify any issues.
kubectl describe node <node-name>
- This command will provide detailed information about the specified node, including its status and any issues that might be affecting it.
kubectl get services
- This command will show the status of all services in the current namespace.
kubectl describe service <service-name>
- This command will provide detailed information about the specified service, including its current status and any issues that might be affecting it.
kubectl get deployments
- This command will show the status of all deployments in the current namespace.
kubectl describe deployment <deployment-name>
- This command will provide detailed information about the specified deployment, including its current status and any issues that might be affecting it.
☸ Kubectl Commands
kubectl version
- This command displays the version of both thekubectl
client and the Kubernetes cluster it is connected to.
kubectl cluster-info
- This command displays information about the Kubernetes cluster, including the cluster API endpoint.
kubectl get
- This command retrieves resources such as pods, services, deployments, and nodes.
kubectl create
- This command creates resources such as pods, services, deployments, and namespaces.
kubectl apply
- This command applies changes to existing resources or creates new ones based on a YAML or JSON file.
kubectl delete
- This command deletes resources such as pods, services, deployments, and namespaces.
kubectl logs
- This command retrieves logs from a container running inside a pod.
kubectl exec
- This command allows you to execute a command inside a container running inside a pod.
kubectl port-forward
- This command creates a tunnel between a local machine and a pod in order to access a service running inside the pod.
kubectl describe
- This command provides detailed information about a Kubernetes resource, such as a pod, service, or deployment.
kubectl edit
- This command allows you to edit the configuration of a Kubernetes resource.
kubectl rollout
- This command allows you to manage rolling updates for deployments.
kubectl scale
- This command allows you to scale the number of replicas of a deployment or a statefulset.
kubectl label
- This command allows you to add or remove labels from Kubernetes resources.
kubectl annotate
- This command allows you to add or remove annotations from Kubernetes resources.
☸ Analyzing logs
kubectl logs <pod-name>
- This command retrieves the logs of a specific pod.
kubectl logs -f <pod-name>
- This command streams the logs of a specific pod in real-time, useful for monitoring logs as they occur.
kubectl logs <pod-name> <container-name>
- This command retrieves the logs of a specific container running in a pod with multiple containers.
kubectl logs -f <pod-name> <container-name>
- This command streams the logs of a specific container running in a pod with multiple containers in real time.
kubectl logs --tail=<number-of-lines> <pod-name>
- This command retrieves the specified number of lines from the end of the logs of a specific pod.
kubectl logs --since=<time> <pod-name>
- This command retrieves the logs of a specific pod since a specified time. The time parameter can be specified in the format of10s
for 10 seconds,1m
for 1 minute,1h
for 1 hour, or1d
for 1 day.
kubectl logs --timestamps <pod-name>
- This command adds timestamps to the logs of a specific pod.
kubectl logs --previous <pod-name>
- This command retrieves the logs of the previous container instance of a specific pod. This is useful for debugging issues after a pod has been restarted.
kubectl logs <pod-name> -c <container-name>
- This command retrieves the logs of a specific container in a specific pod.
kubectl logs <pod-name> -n <namespace-name>
- This command retrieves the logs of a specific pod in a specific namespace.
kubectl logs <pod-name> --all-containers
- This command retrieves the logs of all containers running in a specific pod.
☸ Debugging Container Image
kubectl run -i --tty --image=<image-name> -- sh
- This command starts a new pod using the specified container image, and opens an interactive shell session inside the pod. You can use this shell session to investigate issues with the container image.
kubectl exec -it <pod-name> -- sh
- This command opens an interactive shell session inside an existing pod. You can use this shell session to investigate issues with the container image running inside the pod.
kubectl describe pod <pod-name>
- This command displays detailed information about a specific pod, including the image name and version. You can use this command to verify that the correct container image is being used.
kubectl logs <pod-name>
- This command displays the logs of a specific pod. You can use this command to investigate any error messages or warnings that might be related to the container image.
kubectl port-forward <pod-name> <local-port>:<remote-port>
- This command forwards a local port to a port on the container running inside a specific pod. You can use this command to access the container image directly and investigate issues with the application running inside the container.
kubectl exec -it <pod-name> -- <command>
- This command allows you to execute a specific command inside a container running inside a pod. You can use this command to investigate issues with the container image by running commands such asls
,ps
, andcurl
.
Thanks for Reading!! 😊