Monitoring Node.js applications in Kubernetes environment

Before you monitor Node.js applications in IBM Cloud Private or OpenShift, you must connect the data collector to the server by creating a secret. Then you update your application deployment to monitor the Node.js applications.

Before you begin

If your service account doesn't have access to Kubernetes resources, see Authorizing the data collector to access Kubernetes resources.

Check that you downloaded the configuration package to obtain the server information, for more information, see Obtaining the server configuration information.

Ensure that you installed the data collector, for more information, see Installing the Node.js data collector.

About this task

You can create a secret for the global.environment file and the keyfiles that are extracted from the Monitoring configuration package. Then, you mount this secret when you deploy the application as a Kubernetes deployment.

Procedure

  1. Go to the ibm-cloud-apm-dc-configpack directory where you extract the configuration package in Obtaining the server configuration information, and run the following command to create a secret to connect to the server, for example, name it as icam-server-secret.

    kubectl -n my_namespace create secret generic icam-server-secret \
    --from-file=keyfiles/keyfile.p12 \
    --from-file=global.environment
    

    Where my_namespace is the namespace where you want to create the secret.

  2. Update the Docker file of your Node.js application to get the write access to the work directory by adding the following line:

    RUN chmod 777 nodejs_dir
    

    Where nodejs_dir is the home directory of your Node.js application, for example, /var/apps/acmeair-nodejs.

  3. Build and tag the new docker image of the application and push the new image to the private registry. For example, in the directory where the Docker is located, run the following command:

    docker build -t <application image name>:<image tag>
    
  4. To update the application yaml file to mount the secret, complete the following steps:

    1. Add the volume mount information to the Containers: object in the application deployment yaml file as shown here:

      volumeMounts:
               - mountPath: /opt/ibm/apm/serverconfig
                 name: serverconfig
      
    2. Add the volume information to the Spec: object in the application deployment yaml file as shown here:

      volumes:
           - name: global-environment
             secret:
               secretName: icam-server-secret
               optional: true
      

    Example of a yaml file that is updated:

    apiVersion: extensions/v1beta1
     kind: Deployment
     metadata:
     name: acmeair
     labels:
         app: acmeair
     spec:
     selector:
         matchLabels:
         app: acmeair
         pod: acmeair
     replicas: 1
     template:
         metadata:
         name: acmeair
         labels:
             app: acmeair
             pod: acmeair
         spec:
         containers:
         - name: acmeair
             image: mycluster.icp:8500/default/acmeair:v1
             imagePullPolicy: Always
             ports:
             - containerPort: 3000
             protocol: TCP
             env:        
             - name: KNJ_LOG_TO_FILE
             value: "true"
             - name: KNJ_LOG_LEVEL
             value: "debug"
             - name: APPLICATION_NAME
             value: "acmeair"
             volumeMounts:
             - name: serverconfig
             mountPath: /opt/ibm/apm/serverconfig
         volumes:
         - name: global-environment
           secret:
             secretName: icam-server-secret
             optional: true
    
  5. Update the application yaml file to use the new docker image.