Logs and debug
Viewing Logs in Pods
For a more interactive and user-friendly way to navigate Kubernetes pods and view logs, consider using k9s. This tool provides an efficient and visual way to manage Kubernetes applications directly from the command line, enhancing the experience of viewing logs and managing resources.
To view logs in a pod, use the kubectl logs command. Replace [POD_NAME]
with the specific name of your pod:
kubectl logs [POD_NAME] -n [NAMESPACE]
If you're unsure of the pod's name, first list all pods with:
kubectl get pods -n [NAMESPACE]
Debug Pod
Please note that to be able to run the debug command, your kubectl version must be >= 1.27.
To initiate a debug session for an existing pod on the new architecture, execute the kubectl debug
command as shown below, using the internal-api
pod as an example (replace [NAMESPACE]
with the correct one and find the names of other pods on the Application topology page):
kubectl debug \
--namespace=[NAMESPACE] \
--profile=restricted \
--share-processes \
--container=app \
--copy-to=webapp-debug \
--image=$(kubectl get pods -l app.kubernetes.io/component=internal-api -o jsonpath='{.items[0].spec.containers[0].image}')-debug \
$(kubectl get pods -l app.kubernetes.io/component=internal-api -o jsonpath='{.items[0].metadata.name}')
Where:
--profile=restricted
: Mounts all volumes, config maps, and secrets from the original pod with limited capabilities.--container
: Specifies the debug container.--copy-to
: Names the new debug pod.--image
: Sets the debug image, modifying the original image's tag with a--debug
suffix.
Upon execution, a debug pod named webapp-debug
will be created in your designated namespace, containing a single app
container running the debug image:
To interact with the debug container, use kubectl exec
:
kubectl exec -it webapp-debug -- bash
For diagnostics, you may run:
kubectl exec -it webapp-debug -- python manage.py diagnose_instance
After completing your debugging tasks, remove the debug pod with this command:
kubectl delete pod webapp-debug
Embedded cluster V2
In Embedded cluster V2, you need an additional step to be able to do kubectl
commands.
sudo ./gitguardian shell
Now you can operate the cluster.