Skip to content

Commit fdc0116

Browse files
committed
DD Example app
1 parent 287132e commit fdc0116

16 files changed

+565
-0
lines changed

dd-example/README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# DD Example
2+
This serves as an example project to run to generate metrics, traces, and logs within Datadog.
3+
4+
# Setup / Prerequisites
5+
- [docker](https://docs.docker.com/install/)
6+
- [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
7+
- Start Minikube
8+
- From this directory run:
9+
```
10+
minikube start
11+
eval $(minikube docker-env)
12+
```
13+
- This will start minikube and also set the docker environment to the one minikube offers instead of the one that you may already have installed in your local environment.
14+
15+
# Run the example app
16+
## Build Docker Image
17+
```
18+
docker build -t sample_flask:latest ./raw_files/flask/
19+
docker build -t sample_postgres:latest ./raw_files/postgres/
20+
```
21+
22+
## Put API Key secret in minikube
23+
Replace `API_KEY` with your actual API Key from your Datadog Account.
24+
```
25+
kubectl create secret generic datadog-api --from-literal=token=API_KEY
26+
```
27+
28+
## Deploy to minikube
29+
- Run:
30+
```
31+
kubectl apply -f postgres_deployment.yaml -f flask_deploy.yaml -f datadog-agent.yaml -f kubernetes
32+
```
33+
34+
## Confirm it works & generate traffic
35+
- Grab the `CLUSTER-IP` for flaskapp:
36+
- `kubectl get services`
37+
- Example output:
38+
```
39+
⇒ kubectl get services
40+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
41+
flaskapp ClusterIP 10.104.65.215 <none> 5005/TCP 3m11s
42+
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 32m
43+
postgres ClusterIP 10.99.143.193 <none> 5432/TCP 3m11s
44+
```
45+
- `minikube ssh`
46+
- Hit the flash endpoints:
47+
```
48+
curl http://CLUSTER-IP:5005/
49+
curl http://CLUSTER-IP:5005/bad
50+
curl http://CLUSTER-IP:5005/query
51+
curl http://CLUSTER-IP:5005/log
52+
```
53+
54+
### Observe in Datadog
55+
In a few minutes, you should be able to see metrics, traces, hosts, logs, etc:
56+
- [metric summary page](https://app.datadoghq.com/metric/summary)
57+
- [host map](https://app.datadoghq.com/infrastructure/map)
58+
- [Traces](https://app.datadoghq.com/apm/search)
59+
- [Logs](https://app.datadoghq.com/logs)
60+
- [processes](https://app.datadoghq.com/process)
61+
- [Postgres OOTB Dashboard](https://app.datadoghq.com/screen/integration/235/)
62+
- etc...

dd-example/datadog-agent.yaml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: datadog-agent
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: datadog-agent
9+
template:
10+
metadata:
11+
labels:
12+
app: datadog-agent
13+
name: datadog-agent
14+
spec:
15+
containers:
16+
- image: datadog/agent:latest
17+
imagePullPolicy: Always
18+
name: datadog-agent
19+
ports:
20+
- containerPort: 8125
21+
name: dogstatsdport
22+
protocol: UDP
23+
- containerPort: 8126
24+
hostPort: 8126
25+
name: traceport
26+
protocol: TCP
27+
env:
28+
- name: DD_API_KEY
29+
valueFrom:
30+
secretKeyRef:
31+
name: datadog-api
32+
key: token
33+
- name: KUBERNETES
34+
value: "true"
35+
- name: DD_COLLECT_KUBERNETES_EVENTS
36+
value: "true"
37+
- name: DD_KUBERNETES_KUBELET_HOST
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: status.hostIP
41+
# Logs
42+
- name: DD_LOGS_ENABLED
43+
value: "true"
44+
- name: DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL
45+
value: "true"
46+
- name: DD_PROCESS_AGENT_ENABLED
47+
value: "true"
48+
# APM
49+
- name: DD_APM_ENABLED
50+
value: "true"
51+
# For Trace Search
52+
- name: DD_APM_ANALYZED_SPANS
53+
value: "my-flask-app|flask.request=1,postgres_service|postgres.query=1"
54+
resources:
55+
requests:
56+
memory: "256Mi"
57+
cpu: "200m"
58+
limits:
59+
memory: "256Mi"
60+
cpu: "200m"
61+
volumeMounts:
62+
- name: dockersocket
63+
mountPath: /var/run/docker.sock
64+
- name: procdir
65+
mountPath: /host/proc
66+
readOnly: true
67+
- name: cgroups
68+
mountPath: /host/sys/fs/cgroup
69+
readOnly: true
70+
- name: flasklogs
71+
mountPath: /var/log/flask
72+
readOnly: true
73+
- name: vol-datadog-confd
74+
mountPath: /conf.d
75+
- name: passwd
76+
mountPath: /etc/passwd
77+
readOnly: true
78+
livenessProbe:
79+
exec:
80+
command:
81+
- ./probe.sh
82+
initialDelaySeconds: 15
83+
periodSeconds: 5
84+
volumes:
85+
- hostPath:
86+
path: /var/run/docker.sock
87+
name: dockersocket
88+
- hostPath:
89+
path: /proc
90+
name: procdir
91+
- hostPath:
92+
path: /sys/fs/cgroup
93+
name: cgroups
94+
- hostPath:
95+
path: /var/log/flask
96+
name: flasklogs
97+
- name: vol-datadog-confd
98+
configMap:
99+
name: cm-datadog-confd
100+
- hostPath:
101+
path: /etc/passwd
102+
name: passwd

dd-example/flask_deploy.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: flaskapp
5+
spec:
6+
replicas: 2
7+
selector:
8+
matchLabels:
9+
app: flaskapp
10+
template:
11+
metadata:
12+
labels:
13+
app: flaskapp
14+
spec:
15+
containers:
16+
- name: flaskapp
17+
image: sample_flask:latest
18+
imagePullPolicy: IfNotPresent
19+
ports:
20+
- containerPort: 5005
21+
volumeMounts:
22+
- name: flasklogs
23+
mountPath: /var/log/flask
24+
env:
25+
- name: DD_AGENT_SERVICE_HOST
26+
valueFrom:
27+
fieldRef:
28+
fieldPath: status.hostIP
29+
- name: DD_AGENT_SERVICE_PORT
30+
value: '8126'
31+
volumes:
32+
- hostPath:
33+
path: /var/log/flask
34+
name: flasklogs
35+
36+
---
37+
apiVersion: v1
38+
kind: Service
39+
metadata:
40+
name: flaskapp
41+
spec:
42+
selector:
43+
app: flaskapp
44+
ports:
45+
- name: http
46+
protocol: TCP
47+
port: 5005
48+
---
49+
kind: ConfigMap
50+
apiVersion: v1
51+
metadata:
52+
name: cm-datadog-confd
53+
namespace: default
54+
data:
55+
flasklogs.yaml: |-
56+
init_config:
57+
instances:
58+
logs:
59+
- type: file
60+
path: /var/log/flask/mylog.json
61+
service: flask
62+
source: python
63+
sourcecategory: sourcecode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
3+
kind: ClusterRoleBinding
4+
metadata:
5+
name: kube-state-metrics
6+
roleRef:
7+
apiGroup: rbac.authorization.k8s.io
8+
kind: ClusterRole
9+
name: kube-state-metrics
10+
subjects:
11+
- kind: ServiceAccount
12+
name: kube-state-metrics
13+
namespace: kube-system
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
3+
kind: ClusterRole
4+
metadata:
5+
name: kube-state-metrics
6+
rules:
7+
- apiGroups: [""]
8+
resources:
9+
- configmaps
10+
- secrets
11+
- nodes
12+
- pods
13+
- services
14+
- resourcequotas
15+
- replicationcontrollers
16+
- limitranges
17+
- persistentvolumeclaims
18+
- persistentvolumes
19+
- namespaces
20+
- endpoints
21+
verbs: ["list", "watch"]
22+
- apiGroups: ["extensions"]
23+
resources:
24+
- daemonsets
25+
- deployments
26+
- replicasets
27+
verbs: ["list", "watch"]
28+
- apiGroups: ["apps"]
29+
resources:
30+
- statefulsets
31+
verbs: ["list", "watch"]
32+
- apiGroups: ["batch"]
33+
resources:
34+
- cronjobs
35+
- jobs
36+
verbs: ["list", "watch"]
37+
- apiGroups: ["autoscaling"]
38+
resources:
39+
- horizontalpodautoscalers
40+
verbs: ["list", "watch"]
41+
- apiGroups: ["policy"]
42+
resources:
43+
- poddisruptionbudgets
44+
verbs: ["list", "watch"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: apps/v1
2+
# Kubernetes versions after 1.9.0 should use apps/v1
3+
# Kubernetes versions before 1.8.0 should use apps/v1beta1 or extensions/v1beta1
4+
kind: Deployment
5+
metadata:
6+
name: kube-state-metrics
7+
namespace: kube-system
8+
spec:
9+
selector:
10+
matchLabels:
11+
k8s-app: kube-state-metrics
12+
replicas: 1
13+
template:
14+
metadata:
15+
labels:
16+
k8s-app: kube-state-metrics
17+
spec:
18+
serviceAccountName: kube-state-metrics
19+
containers:
20+
- name: kube-state-metrics
21+
image: quay.io/coreos/kube-state-metrics:v1.4.0
22+
ports:
23+
- name: http-metrics
24+
containerPort: 8080
25+
- name: telemetry
26+
containerPort: 8081
27+
readinessProbe:
28+
httpGet:
29+
path: /healthz
30+
port: 8080
31+
initialDelaySeconds: 5
32+
timeoutSeconds: 5
33+
- name: addon-resizer
34+
image: k8s.gcr.io/addon-resizer:1.8.3
35+
resources:
36+
limits:
37+
cpu: 150m
38+
memory: 50Mi
39+
requests:
40+
cpu: 150m
41+
memory: 50Mi
42+
env:
43+
- name: MY_POD_NAME
44+
valueFrom:
45+
fieldRef:
46+
fieldPath: metadata.name
47+
- name: MY_POD_NAMESPACE
48+
valueFrom:
49+
fieldRef:
50+
fieldPath: metadata.namespace
51+
command:
52+
- /pod_nanny
53+
- --container=kube-state-metrics
54+
- --cpu=100m
55+
- --extra-cpu=1m
56+
- --memory=100Mi
57+
- --extra-memory=2Mi
58+
- --threshold=5
59+
- --deployment=kube-state-metrics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
3+
kind: RoleBinding
4+
metadata:
5+
name: kube-state-metrics
6+
namespace: kube-system
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: Role
10+
name: kube-state-metrics-resizer
11+
subjects:
12+
- kind: ServiceAccount
13+
name: kube-state-metrics
14+
namespace: kube-system
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
3+
kind: Role
4+
metadata:
5+
namespace: kube-system
6+
name: kube-state-metrics-resizer
7+
rules:
8+
- apiGroups: [""]
9+
resources:
10+
- pods
11+
verbs: ["get"]
12+
- apiGroups: ["extensions"]
13+
resources:
14+
- deployments
15+
resourceNames: ["kube-state-metrics"]
16+
verbs: ["get", "update"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: kube-state-metrics
5+
namespace: kube-system

0 commit comments

Comments
 (0)