Create a Sidecar
Container for Syslog
You can configure
a sidecar container for syslog to run in the same pod as NCP. The following
procedure assumes that the syslog agent image is example/rsyslog.
- Configure NCP and NSX node agent to log to a file.In the yaml file for NCP and NSX node agent, set the log_dir parameter and specify the volume to be mounted. For example,[DEFAULT] log_dir = /var/log/nsx-ujo/ ... spec: ... containers: - name: nsx-ncp ... volumeMounts: - name: nsx-ujo-log-dir # Mount path must match [DEFAULT] option "log_dir" mountPath: /var/log/nsx-ujo volumes: ... - name: nsx-ujo-log-dir hostPath: path: /var/log/nsx-ujoYou can change the log file name by setting thelog_fileparameter. The default names arencp.log,nsx_node_agent.log, andnsx_kube_proxy.log. If thelog_diroption is set to a path other than/var/log/nsx-ujo, either a hostPath volume or emptyDir volume must be created and mounted to the corresponding pod spec.
- Make sure the host path exists and is writable by the usernsx-ncp..
- Run the following commands.mkdir -p <host-filesystem-log-dir-path> chmod +w <host-filesystem-log-dir-path>
- Add the usernsx-ncpor change the mode of the host path to 777.useradd -s /bin/bash nsx-ncp chown nsx-ncp:nsx-ncp <host-filesystem-log-dir-path> or chmod 777 <host-filesystem-log-dir-path>
- In the NCP pod's specification yaml file, add a ConfigMap for syslog. For example,kind: ConfigMap metadata: name: rsyslog-config labels: version: v1 data: ncp.conf: | module(load="imfile") ruleset(name="remote") { action(type="omfwd" Protocol="tcp" Target="nsx.example.com" Port="514") stop } input(type="imfile" File="/var/log/nsx-ujo/ncp.log" Tag="ncp" Ruleset="remote"
- In the NCP pod's yaml file, add the rsyslog container and mount the appropriate volumes where rsyslog can find configuration data and read logs from other containers. For example,spec: containers: - name: nsx-ncp ... - name: rsyslog image: example/rsyslog imagePullPolicy: IfNotPresent volumeMounts: - name: rsyslog-config-volume mountPath: /etc/rsyslog.d readOnly: true - name: nsx-ujo-log-dir mountPath: /var/log/nsx-ujo volumes: ... - name: rsyslog-config-volume configMap: name: rsyslog-config - name: nsx-ujo-log-dir hostPath: path: <host-filesystem-log-dir-path>