Kubernetes Pod Logs [ULTIMATE]
GitLab makes it easy to view the logs of running pods in connected Kubernetes clusters. By displaying the logs directly in GitLab, developers can avoid having to manage console tools or jump to a different interface.
- Go to Operations > Environments and find the environment which contains the desired pod, like
- On the Environments page, you should see the status of the environment's pods with Deploy Boards.
- When mousing over the list of pods, a tooltip will appear with the exact pod name and status.
- Click on the desired pod to bring up the logs view, which will contain the last 500 lines for that pod. Support for pods with multiple containers is coming in a future release.
There are a few key requirements in order to be able to use Pod Logs:
- Create or connect a Kubernetes cluster to the project
- A GitLab Runner. If one is not available, they can be easily deployed.
- Ensure a Kubernetes label of
app: $CI_ENVIRONMENT_SLUGis applied to the deployments, replica sets, and pods, where
$CI_ENVIRONMENT_SLUGis the value of the CI variable. This needed to determine the environment a pod belongs to when is more than one. These resources should be contained in the namespace defined in the Kubernetes service setting. The Auto DevOps
.gitlab-ci.ymltemplate has predefined stages and commands to use, and automatically applies the labeling.