1"use strict";(self.webpackChunktroubleshoot_docs=self.webpackChunktroubleshoot_docs||[]).push([["9553"],{2320(e,n,l){l.r(n),l.d(n,{metadata:()=>o,default:()=>h,frontMatter:()=>i,contentTitle:()=>c,toc:()=>r,assets:()=>a});var o=JSON.parse('{"id":"collect/logs","title":"Pod Logs","description":"Including logs from pods in the collected output","source":"@site/docs/collect/logs.md","sourceDirName":"collect","slug":"/collect/logs","permalink":"/docs/collect/logs","draft":false,"unlisted":false,"editUrl":"https://github.com/replicatedhq/troubleshoot/tree/main/docs/docs/collect/logs.md","tags":[{"inline":true,"label":"collect","permalink":"/docs/tags/collect"}],"version":"current","frontMatter":{"title":"Pod Logs","description":"Including logs from pods in the collected output","tags":["collect"]},"sidebar":"docs","previous":{"title":"HTTP Requests","permalink":"/docs/collect/http"},"next":{"title":"Run DaemonSet","permalink":"/docs/collect/run-daemonset"}}'),s=l(4848),t=l(8453);let i={title:"Pod Logs",description:"Including logs from pods in the collected output",tags:["collect"]},c,a={},r=[{value:"Parameters",id:"parameters",level:2},{value:"<code>selector</code> (Required)",id:"selector-required",level:5},{value:"<code>namespace</code> (Optional)",id:"namespace-optional",level:5},{value:"<code>name</code> (Required)",id:"name-required",level:5},{value:"<code>containerNames</code> (Optional)",id:"containernames-optional",level:5},{value:"<code>limits</code> (Optional)",id:"limits-optional",level:5},{value:"<code>limits.maxAge</code>",id:"limitsmaxage",level:5},{value:"<code>limits.maxLines</code>",id:"limitsmaxlines",level:5},{value:"<code>limits.maxBytes</code>",id:"limitsmaxbytes",level:5},{value:"<code>timestamps</code> (Optional)",id:"timestamps-optional",level:5},{value:"Example Collector Definition",id:"example-collector-definition",level:2},{value:"Included resources",id:"included-resources",level:2},{value:"<code>/cluster-resources/pods/logs/[namespace]/[pod-name]/[container-name].log</code>",id:"cluster-resourcespodslogsnamespacepod-namecontainer-namelog",level:3},{value:"<code>/[name]/[pod-name]/[container-name]-errors.json</code>",id:"namepod-namecontainer-name-errorsjson",level:3}];function d(e){let n={a:"a",code:"code",h2:"h2",h3:"h3",h5:"h5",p:"p",pre:"pre",strong:"strong",...(0,t.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"logs"})," collectors can be used to include logs from running pods.\nThis collector can be included multiple times with different label selectors and/or namespaces."]}),"\n",(0,s.jsx)(n.h2,{id:"parameters",children:"Parameters"}),"\n",(0,s.jsxs)(n.p,{children:["In addition to the ",(0,s.jsx)(n.a,{href:"https://troubleshoot.sh/docs/collect/collectors/#shared-properties",children:"shared collector properties"}),", the ",(0,s.jsx)(n.code,{children:"logs"})," collector accepts the following parameters:"]}),"\n",(0,s.jsxs)(n.h5,{id:"selector-required",children:[(0,s.jsx)(n.code,{children:"selector"})," (Required)"]}),"\n",(0,s.jsx)(n.p,{children:"The selector to use to find matching pods.\nIf this selector returns more than one pod, all matching pods will be collected."}),"\n",(0,s.jsxs)(n.p,{children:["Multiple selectors are possible, but the results are a logical ",(0,s.jsx)(n.code,{children:"AND"}),", not a logical ",(0,s.jsx)(n.code,{children:"OR"}),", meaning that the resulting set of pod may not contain the expected results (possibly no results). It is best to use separate collectors to generate individual logs for different service pods."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Example"})}),"\n",(0,s.jsxs)(n.p,{children:["The pod labels in ",(0,s.jsx)(n.code,{children:"service1-deployment.yaml"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:"metadata:\n name: service1\n labels:\n app.kubernetes.io/name: service1\n"})}),"\n",(0,s.jsxs)(n.p,{children:["The collector YAML in ",(0,s.jsx)(n.code,{children:"support-bundle.yaml"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:" collectors:\n - logs:\n selector:\n - app.kubernetes.io/name=service1\n name: service1/logs\n"})}),"\n",(0,s.jsxs)(n.h5,{id:"namespace-optional",children:[(0,s.jsx)(n.code,{children:"namespace"})," (Optional)"]}),"\n",(0,s.jsx)(n.p,{children:"The namespace to search for the pod selector in.\nIf this is not provided, it will default to the current namespace of the context."}),"\n",(0,s.jsxs)(n.h5,{id:"name-required",children:[(0,s.jsx)(n.code,{children:"name"})," (Required)"]}),"\n",(0,s.jsx)(n.p,{children:"Name will be used to create a folder in the support bundle where logs will be saved.\nName can contain slashes to create a path in the support bundle."}
1),"\n",(0,s.jsxs)(n.h5,{id:"containernames-optional",children:[(0,s.jsx)(n.code,{children:"containerNames"})," (Optional)"]}),"\n",(0,s.jsxs)(n.p,{children:["ContainerNames is an array of container names.\nIf specified, logs for each container in the list will be collected.\nIf omitted, logs for ",(0,s.jsx)(n.strong,{children:"all"})," containers in the pod are collected, including init containers."]}),"\n",(0,s.jsxs)(n.h5,{id:"limits-optional",children:[(0,s.jsx)(n.code,{children:"limits"})," (Optional)"]}),"\n",(0,s.jsxs)(n.p,{children:["Provided to limit the size of the logs.\nBy default, this is set to ",(0,s.jsx)(n.code,{children:"maxLines: 10000"}),".\nEither ",(0,s.jsx)(n.code,{children:"maxAge"})," or ",(0,s.jsx)(n.code,{children:"maxLines"})," can be provided, but not both."]}),"\n",(0,s.jsx)(n.h5,{id:"limitsmaxage",children:(0,s.jsx)(n.code,{children:"limits.maxAge"})}),"\n",(0,s.jsxs)(n.p,{children:['The duration of the maximum oldest log to include.\nValid time units are "ns", "us" (or "\xb5s"), "ms", "s", "m", "h".\nFor duration string format see ',(0,s.jsx)(n.a,{href:"https://pkg.go.dev/time#ParseDuration",children:"time.ParseDuration"}),"."]}),"\n",(0,s.jsx)(n.h5,{id:"limitsmaxlines",children:(0,s.jsx)(n.code,{children:"limits.maxLines"})}),"\n",(0,s.jsx)(n.p,{children:"The number of lines to include, starting from the newest."}),"\n",(0,s.jsx)(n.h5,{id:"limitsmaxbytes",children:(0,s.jsx)(n.code,{children:"limits.maxBytes"})}),"\n",(0,s.jsxs)(n.p,{children:["The maximum file size of a collected pod log. Defaults to an integer value of ",(0,s.jsx)(n.code,{children:"5000000"})," bytes, which is 5MB. The value\ncan only be set as an integer value for the ",(0,s.jsx)(n.code,{children:"maxBytes"})," limit."]}),"\n",(0,s.jsxs)(n.h5,{id:"timestamps-optional",children:[(0,s.jsx)(n.code,{children:"timestamps"})," (Optional)"]}),"\n",(0,s.jsxs)(n.p,{children:["When set to ",(0,s.jsx)(n.code,{children:"true"}),", each log line will be prefixed with an RFC3339 timestamp from the Kubernetes API. Defaults to ",(0,s.jsx)(n.code,{children:"false"}),"."]}),"\n",(0,s.jsx)(n.h2,{id:"example-collector-definition",children:"Example Collector Definition"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:"apiVersion: troubleshoot.sh/v1beta2\nkind: SupportBundle\nmetadata:\n name: sample\nspec:\n collectors:\n - logs:\n selector:\n - app=api\n namespace: default\n name: api/container/logs\n containerNames:\n - api\n - node\n limits:\n maxAge: 720h\n - logs:\n selector:\n - app=backend\n namespace: default\n name: backend/container/logs\n containerNames:\n - db\n limits:\n maxLines: 1000\n maxBytes: 5000000\n"})}),"\n",(0,s.jsx)(n.h2,{id:"included-resources",children:"Included resources"}),"\n",(0,s.jsx)(n.p,{children:"When this collector is executed, it will include the following files in a support bundle:"}),"\n",(0,s.jsx)(n.h3,{id:"cluster-resourcespodslogsnamespacepod-namecontainer-namelog",children:(0,s.jsx)(n.code,{children:"/cluster-resources/pods/logs/[namespace]/[pod-name]/[container-name].log"})}),"\n",(0,s.jsxs)(n.p,{children:["The actual log files are stored under ",(0,s.jsx)(n.code,{children:"cluster-resources/pods/logs/"}),". A symlink is created at ",(0,s.jsx)(n.code,{children:"/[name]/[pod-name]/[container-name].log"})," pointing to the actual file, so logs can be accessed via either path."]}),"\n",(0,s.jsx)(n.p,{children:"This will be created for each pod that matches the selector."}),"\n",(0,s.jsx)(n.p,{children:"If any errors are encountered, the following file will be created:"}),"\n",(0,s.jsx)(n.h3,{id:"namepod-namecontainer-name-errorsjson",children:(0,s.jsx)(n.code,{children:"/[name]/[pod-name]/[container-name]-errors.json"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'[\n "failed to get log stream: container node is not valid for pod api-6fd69d8f78-tmtf7"\n]\n'})})]})}function h(e={}){let{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},8453(e,n,l){l.d(n,{R:()=>i,x:()=>c});var o=l(6540);let s={},t=o.createContext(s);function i(e){let n=o.useContext(t);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:i(e.components),o.createElement(t.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.