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.

Procedure

  1. 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-ujo

    You can change the log file name by setting the log_file parameter. The default names are ncp.log, nsx_node_agent.log, and nsx_kube_proxy.log. If the log_dir option 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.

  2. Make sure the host path exists and is writable by the user nsx-ncp..
    1. Run the following commands.
          mkdir -p <host-filesystem-log-dir-path>
          chmod +w <host-filesystem-log-dir-path>
    2. Add the user nsx-ncp or 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>
  3. 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"
  4. 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>