lagoon-logging
by uselagoon
A Helm chart for Kubernetes which installs the Lagoon container and router logs collection system.
About this chart
Lagoon Logging Helm Chart
This chart installs a logging system that will collect and route logs.
Logs are collated into a single index per lagoon project.
Requirements
- Helm 3.2.1 or newer
How to install
Run these commands in the charts/ directory (above lagoon-logging/).
-
Obtain dependency.
helm repo add banzaicloud-stable https://kubernetes-charts.banzaicloud.com helm dependency build lagoon-logging -
Create a
lagoon-logging.values.yamlfile insidecharts/directory containing these fields with the relevant values added. For required values and documentation see the comment block at the end of the chart'svalues.yaml.OpenShift only
You must set allow the fluentbit pods to run in privileged mode, and enable the haproxy logs collector:
fluentbitPrivileged: true openshiftHaproxyLogsCollector: enabled: true -
Test installation.
helm template --debug --namespace lagoon-logging -f ./lagoon-logging.values.yaml lagoon-logging lagoon-logginghelm upgrade --dry-run --install --debug --create-namespace --namespace lagoon-logging -f ./lagoon-logging.values.yaml lagoon-logging lagoon-logging -
Run installation.
helm upgrade --install --debug --create-namespace --namespace lagoon-logging -f ./lagoon-logging.values.yaml lagoon-logging lagoon-loggingOpenShift only
Give the various serviceaccounts permissions required:
oc project lagoon-logging # fluentd statefulset serviceaccount (logging-operator chart) oc adm policy add-scc-to-user nonroot -z lagoon-logging-fluentd # fluentbit daemonset serviceaccount (logging-operator chart) oc adm policy add-scc-to-user privileged -z lagoon-logging-fluentbit # logs-dispatcher statefulset serviceaccount (lagoon-logging chart) oc adm policy add-scc-to-user anyuid -z lagoon-logging-logs-dispatcherAnd make the project network global:
oc adm pod-network make-projects-global lagoon-logging -
Update application-logs and router-logs services
The
application-logsservice in thelagoonnamespace needs to be updated to point to thelagoon-logging-logs-dispatcherservice in thelagoon-loggingnamespace (or wherever you've installed it).
View logs
For namespaces without a lagoon.sh/project label
Logs will appear in indices matching these patterns:
application-logs-*_$CLUSTERNAME-*
container-logs-*_$CLUSTERNAME-*
router-logs-*_$CLUSTERNAME-*
e.g. if clusterName: test1
application-logs-*_test1-*
container-logs-*_test1-*
router-logs-*_test1-*
For namespaces with a lagoon.sh/project label
Logs will appear in indices matching these patterns:
application-logs-$PROJECT-*
container-logs-$PROJECT-*
router-logs-$PROJECT-*
e.g. if lagoon.sh/project: drupal-example
application-logs-drupal-example-*
container-logs-drupal-example-*
router-logs-drupal-example-*
How to upgrade
NOTE: If the logging-operator chart upgrade doesn't work, just uninstall the helm release and install it again. Logs won't be lost since fluentbit will send the contents of the log files once it is reinstalled.
helm upgrade --debug --namespace lagoon-logging --reuse-values lagoon-logging lagoon-logging
Generating certificates
Some components of this chart use server or client TLS authentication.
These can be generated using the instructions in the lagoon-logs-concentrator chart README.
The convention for SAN and CN naming is along the lines of:
logs-dispatcher.cluster1.example.comfor the lagoon-logging "client" andlogs-concentrator.cluster2.example.comfor thelagoon-logs-concentrator"server".cdn.cluster1.example.comfor the CDN "client" andcdn-logs-collector.cluster1.example.comfor thecdn-logs-collector"server".
Log export
The logs-dispatcher includes support for sending logs to external sinks such as cloudwatch or S3.
This feature uses the fluentd copy plugin, so see that link for syntax.
For example configure the exportLogs value like so:
exportLogs:
s3.conf: |
<store ignore_error>
@type s3
...
</store>
cloudwatch.conf: |
<store ignore_error>
@type cloudwatch_logs
...
</store>
IMPORTANT: use ignore_error so that the main log flow to elasticsearch is not interrupted.
Optionally you may also set enableDefaultForwarding: false to disable the default logs forwarding to logs-concentrator and Elasticsearch.
Local testing
This is useful for quick local testing of fluent.conf snippets.
Prerequisite: Ruby gems set up correctly with gems /bin dir in $PATH.
Install fluentd.
gem install fluentd
Create fluent.conf:
<source>
@type forward
@id in_router_openshift
tag "lagoon.test.router.openshift.unmatched"
</source>
<filter lagoon.*.router.openshift.unmatched>
@type grep
<exclude>
key message
pattern /my_test_pattern/
</exclude>
</filter>
# keep the rest
<filter lagoon.*.router.openshift.unmatched>
@type record_modifier
<record>
index_name router-logs-openshift_parse_error_test-${Time.at(time).strftime("%Y.%m")}
</record>
</filter>
<match lagoon.**>
@type stdout
</match>
Start fluentd:
fluentd -c fluent.conf
Send some test logs:
fluent-cat --none tag.discard < sample.log
Deploy lagoon-logging with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has lagoon-logging on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartlagoon-logging is pinned at v0.99.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply