Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes monitoring docs #151

Merged
merged 47 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
67dbb71
Add draft outline for Kubernetes monitoring guide
dedemorton Sep 9, 2020
6d27847
Add changes from the review
dedemorton Sep 24, 2020
4a762dd
Create separate files
dedemorton Sep 24, 2020
96dd952
Add files
dedemorton Sep 24, 2020
16ea901
Make APM section owner TBD
dedemorton Sep 29, 2020
7148360
Assign "monitor logs" section to ChrsMark
dedemorton Sep 29, 2020
0de1caf
Assign metric monitoring section to ChrsMark
dedemorton Sep 29, 2020
1cb0db2
Merge branch 'master' into k8s_monitoring_docs
dedemorton Oct 8, 2020
238206d
Add logs section (#154)
ChrsMark Oct 12, 2020
521d88c
Add metrics part (#163)
ChrsMark Oct 12, 2020
da25ff8
Add discrete tag to fix build issues
dedemorton Oct 12, 2020
599b77c
Edits in progress
dedemorton Oct 15, 2020
8b464dd
Remove link to topic that no longer exists
dedemorton Oct 15, 2020
c6df8df
More edits
dedemorton Oct 27, 2020
7004542
Merge branch 'master' into k8s_monitoring_docs
dedemorton Oct 27, 2020
efda696
In-progress changes
dedemorton Oct 28, 2020
1c82a48
save changes
dedemorton Oct 28, 2020
fd5c653
Add more edits and fixes from testing
dedemorton Dec 4, 2020
90e7e69
Fix link
dedemorton Dec 4, 2020
3b8e75e
Fix broken doc build
dedemorton Dec 4, 2020
1d29ae2
Fix issues found during testing
dedemorton Dec 5, 2020
7e041c4
Add fixes from testing metrics monitoring
dedemorton Dec 8, 2020
2bbef81
Change from numbered list to sections
dedemorton Dec 8, 2020
2c76845
Add draft overview and architecture digram
dedemorton Dec 10, 2020
fb62658
Fix mistake in diagram
dedemorton Dec 10, 2020
a4c7887
Clean up icons
dedemorton Dec 10, 2020
c5ba1b4
Clean up topics
dedemorton Dec 11, 2020
8054dd1
Remove comment markers
dedemorton Dec 11, 2020
a340c8a
Move before you begin section
dedemorton Dec 11, 2020
9967a76
Add feedback from ChrsMark
dedemorton Dec 15, 2020
8b5bdbe
Update docs/en/observability/monitor-k8s/monitor-k8s-logs.asciidoc
dedemorton Dec 16, 2020
29e5269
Resolve review feedback from bmorelli25
dedemorton Dec 16, 2020
edab83c
Resolve review feedback from masci and fix para about dashboards
dedemorton Dec 16, 2020
fbe7427
Add APM to diagram
dedemorton Dec 19, 2020
54b780c
Apply suggestions from code review
dedemorton Dec 19, 2020
7f562cf
Apply suggestions from DanRoscigno
dedemorton Dec 21, 2020
255c8f8
Add changes from danroscigno's review
dedemorton Dec 22, 2020
9928e3e
docs: Add basic APM on Kubernetes steps (#301)
bmorelli25 Dec 22, 2020
cea2424
Merge branch 'master' of github.com:elastic/observability-docs into k…
bmorelli25 Dec 23, 2020
10a4ea8
docs: feedback from dan
bmorelli25 Dec 23, 2020
2b2fb98
Update docs/en/observability/monitor-k8s/monitor-k8s-application-perf…
bmorelli25 Jan 4, 2021
b975019
Update secret token based on Eyal's feedback
bmorelli25 Jan 4, 2021
aeb03fc
Update docs/en/observability/monitor-k8s/monitor-k8s-application-perf…
bmorelli25 Jan 4, 2021
81a9ed6
docs: add no-code instrumentation for dotnet
bmorelli25 Jan 5, 2021
0cf72ab
Apply additional suggestions from DanRoscigno
dedemorton Jan 12, 2021
9817904
Apply suggestions from code review
dedemorton Jan 13, 2021
dea74c3
Remove outdated todos
dedemorton Jan 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[discrete]
== Part 6: Diagnose bottlenecks and other issues

[Author: TBD? PM?]

TODO: Describe how to explore a real problem by navigating
observability UIs and dashboards. This section should showcase the power of
using our observability solution (being able to correlate logs, metrics, and
traces to solve a specific, real-world problem). The section title needs to
match whatever scenario we decide to discuss.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
[discrete]
bmorelli25 marked this conversation as resolved.
Show resolved Hide resolved
[[monitor-kubernetes-application-performance]]
== Part 3: Monitor application performance

Quickly triage and troubleshoot application performance problems with the help of Elastic
application performance monitoring (APM).

Think of a latency spike -- APM can help you narrow the scope of your investigation to a single service.
Because you've also ingested and correlated logs and metrics, you can then link the problem to CPU and memory utilization or error log entries of a particular Kubernetes pod.

[discrete]
=== Step 1: Set up APM Server

Application monitoring data is streamed from your applications running in Kubernetes to APM Server,
where it is validated, processed, and transformed into {es} documents.

There are many ways to deploy APM Server when working with Kubernetes,
but this guide assumes that you're using our hosted {ess} on {ecloud}.
If you haven't done so already, enable APM Server in the {ess-console}[{ess} console].

If you want to manage APM Server yourself, there are a few alternative options:

[%collapsible]
.Expand alternatives
====
* {eck-ref}/[Elastic Cloud on Kubernetes (ECK)] -- The Elastic recommended approach for managing
APM Server deployed with Kubernetes.
Built on the Kubernetes Operator pattern, ECK extends basic Kubernetes orchestration capabilities
to support the setup and management of APM Server on Kubernetes.

* Deploy APM Server as a DaemonSet -- Ensure a running instance of APM Server on each node in your cluster.
Useful when all pods in a node should share a single APM Server instance.

* Deploy APM Server as a sidecar -- For environments that should not share an APM Server,
like when directing traces from multiple applications to separate {es} clusters.

* {apm-server-ref-v}/installing.html[Download and install APM Server] -- The classic, non-Kubernetes option.
====

[discrete]
=== Step 2: Save your secret token

A {apm-server-ref-v}/secret-token.html[secret token] is used to secure communication between APM agents
and APM Server. On the {ecloud} deployment page, select *APM* and copy your APM Server secret token.
To avoid exposing the secret token, you can store it in a Kubernetes secret. For example:

[source, cmd]
----
kubectl create secret generic apm-secret --from-literal=ELASTIC_APM_SECRET_TOKEN=asecretpassword --namespace=kube-system <1>
----
<1> Create the secret in the same namespace that you'll be deploying your applications in.

bmorelli25 marked this conversation as resolved.
Show resolved Hide resolved
If you're managing APM Server yourself,
see {apm-server-ref-v}/secret-token.html[secret token] for instructions on how to set up your secret token.

If you are using ECK to set up APM Server, the operator automatically generates an `{APM-server-name}-apm-token` secret for you.

[discrete]
=== Step 3: Install and configure APM Agents

In most cases, setting up APM agents and thereby instrumenting your applications
is as easy as installing a library and adding a few lines of code.

Select your application's language for details:

include::{shared}/install-apm-agents-kube/widget.asciidoc[]

[discrete]
=== Step 4: Configure Kubernetes data

In most instances, APM agents automatically read Kubernetes data from inside the
container and send it to APM Server.
If this is not the case, or if you wish to override this data,
you can set environment variables for the agents to read.
These environment variable are set via the https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api[Downward API]
in your kubernetes pod spec:

[source,yml]
----
# ...
containers:
- name: your-app-container
env:
# ...
- name: KUBERNETES_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: KUBERNETES_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KUBERNETES_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
----

The table below maps these environment variables to the APM metadata event field:

[options="header"]
|=====
|Environment variable |Metadata field name
|KUBERNETES_NODE_NAME |system.kubernetes.node.name
|KUBERNETES_POD_NAME |system.kubernetes.pod.name
|KUBERNETES_NAMESPACE |system.kubernetes.namespace
|KUBERNETES_POD_UID |system.kubernetes.pod.uid
|=====

[discrete]
=== Step 5: Deploy your application

APM agents are deployed with your application.

[%collapsible]
.Resource configuration file example
====

A complete resource configuration file based on the previous steps.

[source,yml]
----
apiVersion: apps/v1
kind: Deployment
metadata:
name: <<your-app>>
namespace: kube-system
labels:
app: <<your-app>>
service: <<your-app>>
spec:
replicas: 1
selector:
matchLabels:
app: <<your-app>>
template:
metadata:
labels:
app: <<your-app>>
service: <<your-app>>
spec:
dnsPolicy: ClusterFirstWithHostNet
volumes:
- name: elastic-apm-agent
emptyDir: {}
initContainers:
- name: elastic-java-agent
image: docker.elastic.co/observability/apm-agent-java:1.12.0
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
command: ['cp', '-v', '/usr/agent/elastic-apm-agent.jar', '/elastic/apm/agent']
containers:
- name: <<your-app>>
image: <<your-app>>
volumeMounts:
- mountPath: /elastic/apm/agent
name: elastic-apm-agent
env:
- name: ELASTIC_APM_SERVER_URL
value: "apm-server-url-goes-here"
- name: ELASTIC_APM_SECRET_TOKEN
valueFrom:
secretKeyRef:
name: apm-secret
key: ELASTIC_APM_SECRET_TOKEN
- name: ELASTIC_APM_SERVICE_NAME
value: "petclinic"
- name: ELASTIC_APM_APPLICATION_PACKAGES
value: "org.springframework.samples.petclinic"
- name: ELASTIC_APM_ENVIRONMENT
value: test
- name: JAVA_TOOL_OPTIONS
value: -javaagent:/elastic/apm/agent/elastic-apm-agent.jar
- name: KUBERNETES_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: KUBERNETES_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KUBERNETES_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
----
====

[source,cmd]
----
kubectl apply -f demo.yml
----

[discrete]
=== View your traces in Kibana

To view your application's trace data, open Kibana and go to *Observability* *>* *APM*.

The APM app allows you to monitor your software services and applications in real-time:
visualize detailed performance information on your services, identify and analyze errors,
and monitor host-level and agent-specific metrics like JVM and Go runtime metrics.

[screenshot]
image::images/spring-apm-app-2.png[APM app kubernetes]

Having access to application-level insights with just a few clicks can drastically decrease the time you spend debugging errors, slow response times, and crashes.

Best of all, because Kubernetes environment variables have been mapped to APM metadata events,
you can filter your trace data by Kubernetes `namespace`, `node.name`, `pod.name`, and `pod.uid`.

[screenshot]
image::images/apm-app-kubernetes-filter.png[APM app kubernetes]
Loading