Skip to content

Commit c97e7f5

Browse files
authored
Merge pull request #188 from kube-logging/tailer-webhook
Tailer webhook
2 parents 34f0f38 + 62744e8 commit c97e7f5

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

content/docs/configuration/extensions/tailer-webhook.md

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,54 @@ Cons:
2323

2424
## Enable webhooks in Logging operator {#enable-webhooks}
2525

26-
> We recommend using `cert-manager` to manage your certificates. Since using `cert-manager` is not part of this article, we assume you already have valid certs.
26+
> We recommend using `cert-manager` to manage your certificates. Below is a really simple command that bootstraps generates the required resources for the `tailer-webhook`.
27+
### Issuing certificates using `cert-manager` {#issue-certificate-cert-manager}
28+
29+
Follow the [official installation guide](https://cert-manager.io/docs/installation/).
30+
31+
Once installed the following commands should allow you to create the required certificate for the webhook.
32+
33+
```bash
34+
kubectl apply -f - <<EOF
35+
apiVersion: cert-manager.io/v1
36+
kind: ClusterIssuer
37+
metadata:
38+
name: selfsigned-issuer
39+
spec:
40+
selfSigned: {}
41+
---
42+
apiVersion: cert-manager.io/v1
43+
kind: Certificate
44+
metadata:
45+
name: webhook-tls
46+
namespace: logging
47+
spec:
48+
isCA: true
49+
commonName: my-selfsigned-ca
50+
secretName: webhook-tls
51+
privateKey:
52+
algorithm: ECDSA
53+
size: 256
54+
dnsNames:
55+
- sample-webhook.banzaicloud.com
56+
- logging-webhooks.logging.svc
57+
usages:
58+
- server auth
59+
issuerRef:
60+
name: selfsigned-issuer
61+
kind: ClusterIssuer
62+
group: cert-manager.io
63+
---
64+
apiVersion: cert-manager.io/v1
65+
kind: ClusterIssuer
66+
metadata:
67+
name: my-ca-issuer
68+
spec:
69+
ca:
70+
secretName: webhook-tls
71+
EOF
72+
```
73+
2774

2875
You will require the following things:
2976

@@ -107,14 +154,15 @@ metadata:
107154
namespace: logging
108155
labels:
109156
app: sample-webhook
157+
annotations:
158+
cert-manager.io/inject-ca-from: logging/webhook-tls
110159
webhooks:
111160
- name: sample-webhook.banzaicloud.com
112161
clientConfig:
113162
service:
114163
name: logging-webhooks
115164
namespace: logging
116165
path: "/tailer-webhook"
117-
caBundle: $(kubectl get secret webhook-tls -n logging -o json | jq -r '.data["ca.crt"]')
118166
rules:
119167
- operations: [ "CREATE" ]
120168
apiGroups: [""]
@@ -159,7 +207,7 @@ To trigger the webhook, add the following annotation to the pod metadata:
159207

160208
### File tailer example
161209

162-
The following example creates a pod that is running a shell in infinite loop that appends the `date` command's output to a file every second. The annotation `sidecar.logging-extensions.banzaicloud.io/tail` notifies Logging operator to attach a sidecar container to the pod. The sidecar tails the `/legacy-logs/date.log` file and sends its output to the stdout.
210+
The following example creates a pod that is running a shell in infinite loop that appends the `date` command's output to a file every second. The annotation `sidecar.logging-extensions.banzaicloud.io/tail` notifies Logging operator to attach a sidecar container to the pod. The sidecar tails the `/var/log/date` file and sends its output to the stdout.
163211

164212
```yaml
165213
apiVersion: v1
@@ -170,16 +218,13 @@ metadata:
170218
spec:
171219
containers:
172220
- image: debian
173-
name: sample-container
174-
command: ["/bin/sh", "-c"]
175-
args:
176-
- while true; do
177-
date >> /var/log/date;
178-
sleep 1;
179-
done
180-
- image: debian
181-
name: sample-container2
182-
...
221+
name: sample-container
222+
command: ["/bin/sh", "-c"]
223+
args:
224+
- while true; do
225+
date >> /var/log/date;
226+
sleep 1;
227+
done
183228
```
184229

185230
After you have created the pod with the required annotation, make sure that the `test-pod` contains two containers by running `kubectl get pod`
@@ -201,15 +246,15 @@ Expected output:
201246

202247
```bash
203248
[
204-
"test",
205-
"legacy-logs-date-log"
249+
"sample-container",
250+
"sample-container-var-log-date"
206251
]
207252
```
208253

209254
Check the logs of the `test` container. Since it writes the logs into a file, it does not produce any logs on stdout.
210255

211256
```bash
212-
kubectl logs test-pod test; echo $?
257+
kubectl logs test-pod sample-container; echo $?
213258
```
214259

215260
Expected output:

0 commit comments

Comments
 (0)