diff --git a/filebeat/README.md b/filebeat/README.md index d8b57c9bd..f19164c9d 100644 --- a/filebeat/README.md +++ b/filebeat/README.md @@ -49,6 +49,7 @@ helm install --name filebeat elastic/filebeat --set imageTag=7.4.0 | `extraVolumeMounts` | Templatable string of additional volumeMounts to be passed to the `tpl` function | `""` | | `extraVolumes` | Templatable string of additional volumes to be passed to the `tpl` function | `""` | | `hostPathRoot` | Fully-qualified [hostPath](https://kubernetes.io/docs/concepts/storage/volumes/#hostpath) that will be used to persist Filebeat registry data | `/var/lib` | +| `hostNetworking` | Use host networking in the daemonset so that hostname is reported correctly | `image` | The Filebeat docker image | `docker.elastic.co/beats/filebeat` | | `imageTag` | The Filebeat docker image tag | `7.4.0` | | `imagePullPolicy` | The Kubernetes [imagePullPolicy](https://kubernetes.io/docs/concepts/containers/images/#updating-images) value | `IfNotPresent` | diff --git a/filebeat/templates/daemonset.yaml b/filebeat/templates/daemonset.yaml index ff0b9bc8b..3943c26b5 100644 --- a/filebeat/templates/daemonset.yaml +++ b/filebeat/templates/daemonset.yaml @@ -49,6 +49,10 @@ spec: {{- end }} serviceAccountName: {{ template "serviceAccount" . }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} + {{- if .Values.hostNetworking }} + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + {{- end }} volumes: {{- range .Values.secretMounts }} - name: {{ .name }} @@ -111,6 +115,10 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName {{- if .Values.extraEnvs }} {{ toYaml .Values.extraEnvs | indent 8 }} {{- end }} diff --git a/filebeat/tests/filebeat_test.py b/filebeat/tests/filebeat_test.py index 5bd288921..08191751b 100644 --- a/filebeat/tests/filebeat_test.py +++ b/filebeat/tests/filebeat_test.py @@ -2,7 +2,6 @@ import sys sys.path.insert(1, os.path.join(sys.path[0], '../../helpers')) from helpers import helm_template -import yaml project = 'filebeat' name = 'release-name-' + project @@ -86,6 +85,20 @@ def test_override_the_default_update_strategy(): r = helm_template(config) assert r['daemonset'][name]['spec']['updateStrategy']['type'] == 'OnDelete' + +def test_host_networking(): + config = ''' +hostNetworking: true +''' + r = helm_template(config) + assert r['daemonset'][name]['spec']['template']['spec']['hostNetwork'] is True + config = ''' +hostNetworking: false +''' + r = helm_template(config) + assert 'hostNetwork' not in r['daemonset'][name]['spec']['template']['spec'] + + def test_setting_a_custom_service_account(): config = ''' serviceAccount: notdefault diff --git a/filebeat/values.yaml b/filebeat/values.yaml index 1e6af7585..515958f3a 100755 --- a/filebeat/values.yaml +++ b/filebeat/values.yaml @@ -12,6 +12,7 @@ filebeatConfig: in_cluster: true output.elasticsearch: + host: '${NODE_NAME}' hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}' # Extra environment variables to append to the DaemonSet pod spec. @@ -32,7 +33,7 @@ extraVolumes: "" # Root directory where Filebeat will write data to in order to persist registry data across pod restarts (file position and other metadata). hostPathRoot: /var/lib - +hostNetworking: true image: "docker.elastic.co/beats/filebeat" imageTag: "7.4.0" imagePullPolicy: "IfNotPresent"