Skip to content

Commit d910d1b

Browse files
- minor security enhancements in helm chart (#24)
- minor best-practices/linting (E.g. using select{} instead of a ifinite loop with sleep, using log.Print vs fmt.Print, formatted the imports, etc.) - minor readme changes (linting for links and header sizes, removal/change for dead link(s), and addition of some other log collectors like Promtail and Logstash) - bump go to 1.20 to pull in some security fixes - bump k8s.io deps to v0.24.15 (note that this version is about to become non-maintained, but still is for now)
1 parent bbf4fd8 commit d910d1b

File tree

7 files changed

+87
-220
lines changed

7 files changed

+87
-220
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<img src="https://raw.githubusercontent.com/max-rocket-internet/k8s-event-logger/master/img/k8s-logo.png" width="100">
44

5-
This tool simply watches Kubernetes Events and logs them to stdout in JSON to be collected and stored by your logging solution, e.g. [fluentd](https://github.com/fluent/fluentd-kubernetes-daemonset) or [fluent-bit](https://fluentbit.io/). Other tools exist for persisting Kubernetes Events, such as Sysdig, Datadog or Google's [event-exporter](https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/event-exporter) but this tool is open and will work with any logging solution.
5+
This tool simply watches Kubernetes Events and logs them to stdout in JSON to be collected and stored by your logging solution, e.g. [fluentd](https://github.com/fluent/fluentd-kubernetes-daemonset), [fluent-bit](https://fluentbit.io/), [Filebeat](https://www.elastic.co/guide/en/beats/filebeat/current/running-on-kubernetes.html), or [Promtail](https://grafana.com/docs/loki/latest/clients/promtail/). Other tools exist for persisting Kubernetes Events, such as Sysdig, Datadog, or Google's [event-exporter](https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/event-exporter) but this tool is open and will work with any logging solution.
66

7-
### Why?
7+
## Why?
88

99
Events in Kubernetes log very important information. If are trying to understand what happened in the past then these events show clearly what your Kubernetes cluster was thinking and doing. Some examples:
1010

@@ -17,7 +17,7 @@ The problem is that these events are simply API objects in Kubernetes and are on
1717

1818
Example of events:
1919

20-
```
20+
```text
2121
39m Normal UpdatedLoadBalancer Service Updated load balancer with new hosts
2222
40m Normal SuccessfulDelete DaemonSet Deleted pod: ingress02-nginx-ingress-controller-vqqjp
2323
41m Normal ScaleDown Node node removed by cluster autoscaler
@@ -30,40 +30,46 @@ Example of events:
3030
58m Normal CREATE ConfigMap ConfigMap default/ingress02-nginx-ingress-controller
3131
```
3232

33-
### Installation
33+
## Installation
3434

3535
Use the [Helm](https://helm.sh/) chart from this repo:
3636

37-
```
37+
```sh
3838
helm install chart/
3939
```
4040

4141
Or use the chart from [deliveryhero/helm-charts/stable/k8s-event-logger](https://github.com/deliveryhero/helm-charts/tree/master/stable/k8s-event-logger):
4242

43-
```
43+
```sh
4444
helm repo add deliveryhero https://charts.deliveryhero.io/
4545
helm install deliveryhero/k8s-event-logger
4646
```
4747

48-
Or use the docker image [maxrocketinternet/k8s-event-logger](https://hub.docker.com/r/maxrocketinternet/k8s-event-logger)
48+
Or use the pre-built image [maxrocketinternet/k8s-event-logger][pre-built image]
4949

50-
#### Building a container image
50+
### Building a container image
5151

52-
If you're unable to use the [prebuilt][image] docker image, you can build it yourself:
52+
If you're unable to use the [pre-built image], you can build it yourself:
5353

5454
```sh
55-
make IMG=maxrocketinternet/k8s-event-logger TAG=latest
55+
make all IMG=<your-container-registry>/k8s-event-logger TAG=latest
5656
```
5757

58-
This uses `docker buildx` to create a [multi-platform image][]. To set up your build host system to be able to build these images, see [this guide][qemu-binfmt].
58+
This uses `docker buildx` to create a [multi-platform image]. To set up your build host system to be able to build these images, see [this guide][multi-platform image] or `make all` and review the Makefile for what it does.
5959

6060
[multi-platform image]: https://docs.docker.com/build/building/multi-platform/
61-
[qemu-binfmt]: https://docs.nvidia.com/datacenter/cloud-native/playground/x-arch.html
61+
[pre-built image]: https://hub.docker.com/r/maxrocketinternet/k8s-event-logger
6262

63-
### Testing
63+
Or to just build locally for testing without multi-arch support (but also doesn't require a registry):
64+
65+
```sh
66+
docker build --tag localhost/k8s-event-logger .
67+
```
68+
69+
## Testing
6470

6571
Run it:
6672

67-
```
73+
```sh
6874
go run main.go
6975
```

chart/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
2-
appVersion: "1.8"
3-
version: "1.1.3"
2+
appVersion: "1.9"
3+
version: "1.2.0"
44
description: A tool to log k8s events to stdout in JSON
55
home: https://github.com/max-rocket-internet/k8s-event-logger
66
name: k8s-event-logger
@@ -14,6 +14,6 @@ icon: https://github.com/kubernetes/kubernetes/raw/master/logo/logo.png
1414
keywords:
1515
- events
1616
- logging
17-
- Auditing
17+
- auditing
1818
sources:
1919
- https://github.com/max-rocket-internet/k8s-event-logger

chart/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# k8s-event-logger
22

3-
This chart runs a pod that simply watches Kubernetes Events and logs them to stdout in JSON to be collected and stored by your logging solution, e.g. [fluentd](https://github.com/helm/charts/tree/master/stable/fluentd) or [fluent-bit](https://github.com/helm/charts/tree/master/stable/fluent-bit).
3+
This chart runs a pod that simply watches Kubernetes Events and logs them to stdout in JSON to be collected and stored by your logging solution, e.g. [fluentd](https://github.com/fluent/fluentd-kubernetes-daemonset), [fluent-bit](https://fluentbit.io/), [Filebeat](https://www.elastic.co/guide/en/beats/filebeat/current/running-on-kubernetes.html), or [Promtail](https://grafana.com/docs/loki/latest/clients/promtail/). Other tools exist for persisting Kubernetes Events, such as Sysdig, Datadog, or Google's [event-exporter](https://github.com/GoogleCloudPlatform/k8s-stackdriver/tree/master/event-exporter) but this tool is open and will work with any logging solution.
44

5-
https://github.com/max-rocket-internet/k8s-event-logger
5+
[Source code](https://github.com/max-rocket-internet/k8s-event-logger)
66

77
Events in Kubernetes log very important information. If are trying to understand what happened in the past then these events show clearly what your Kubernetes cluster was thinking and doing. Some examples:
88

@@ -15,22 +15,22 @@ The problem is that these events are simply API objects in Kubernetes and are on
1515

1616
## Prerequisites
1717

18-
- Kubernetes 1.8+
18+
- Kubernetes 1.23+
1919

2020
## Installing the Chart
2121

2222
To install the chart with the release name `my-release` and default configuration:
2323

24-
```shell
25-
$ helm install --name my-release stable/k8s-event-logger
24+
```sh
25+
helm install --name my-release stable/k8s-event-logger
2626
```
2727

2828
## Uninstalling the Chart
2929

3030
To delete the chart:
3131

32-
```shell
33-
$ helm delete my-release
32+
```sh
33+
helm delete my-release
3434
```
3535

3636
## Configuration
@@ -56,6 +56,6 @@ The following table lists the configurable parameters for this chart and their d
5656

5757
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install` or provide a YAML file containing the values for the above parameters:
5858

59-
```shell
60-
$ helm install --name my-release stable/k8s-event-logger --values values.yaml
59+
```sh
60+
helm install --name my-release stable/k8s-event-logger --values values.yaml
6161
```

chart/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ spec:
3535
securityContext:
3636
readOnlyRootFilesystem: true
3737
runAsNonRoot: true
38+
runAsUser: 10001
39+
runAsGroup: 10001
40+
allowPrivilegeEscalation: false
41+
capabilities:
42+
drop:
43+
- ALL
44+
seccompProfile:
45+
type: RuntimeDefault
3846
env:
3947
{{- range $key, $value := .Values.env }}
4048
- name: {{ $key }}

go.mod

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
module github.com/max-rocket-internet/k8s-event-logger
22

3-
go 1.18
3+
go 1.20
44

55
require (
6-
k8s.io/api v0.24.1
7-
k8s.io/apimachinery v0.24.1
8-
k8s.io/client-go v0.24.1
6+
k8s.io/api v0.24.15
7+
k8s.io/apimachinery v0.24.15
8+
k8s.io/client-go v0.24.15
99
)
1010

1111
require (
12-
github.com/PuerkitoBio/purell v1.1.1 // indirect
13-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
1412
github.com/davecgh/go-spew v1.1.1 // indirect
15-
github.com/emicklei/go-restful v2.15.0+incompatible // indirect
1613
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
1714
github.com/go-logr/logr v1.2.3 // indirect
1815
github.com/go-openapi/jsonpointer v0.19.5 // indirect
@@ -31,21 +28,22 @@ require (
3128
github.com/modern-go/reflect2 v1.0.2 // indirect
3229
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3330
github.com/spf13/pflag v1.0.5 // indirect
34-
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
31+
golang.org/x/net v0.8.0 // indirect
3532
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect
36-
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
37-
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
38-
golang.org/x/text v0.3.7 // indirect
33+
golang.org/x/sys v0.6.0 // indirect
34+
golang.org/x/term v0.6.0 // indirect
35+
golang.org/x/text v0.8.0 // indirect
3936
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
4037
google.golang.org/appengine v1.6.7 // indirect
4138
google.golang.org/protobuf v1.28.0 // indirect
4239
gopkg.in/inf.v0 v0.9.1 // indirect
40+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
4341
gopkg.in/yaml.v2 v2.4.0 // indirect
4442
gopkg.in/yaml.v3 v3.0.1 // indirect
4543
k8s.io/klog/v2 v2.60.1 // indirect
4644
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60 // indirect
4745
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
4846
sigs.k8s.io/json v0.0.0-20220525155127-227cbc7cc124 // indirect
49-
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
47+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
5048
sigs.k8s.io/yaml v1.3.0 // indirect
5149
)

0 commit comments

Comments
 (0)