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
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.
Go to the
ibm-cloud-apm-dc-configpackdirectory 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
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.
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
nodejs_diris the home directory of your Node.js application, for example,
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>
To update the application
yamlfile to mount the secret, complete the following steps:
Add the volume mount information to the
Containers:object in the application deployment
yamlfile as shown here:
volumeMounts: - mountPath: /opt/ibm/apm/serverconfig name: serverconfig
Add the volume information to the
Spec:object in the application deployment
yamlfile as shown here:
volumes: - name: global-environment secret: secretName: icam-server-secret optional: true
Example of a
yamlfile 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
Update the application
yamlfile to use the new docker image.