Monitoring Go applications in Kubernetes environment

Before you monitor Go applications in Kubernetes environment, you must connect the data collector to the server by creating a secret. Then, you update your application deployment to monitor the Go applications.

Before you begin

About this task

To enable the Go data collector, you need to update the application code to import the Go data collector package, rebuild the application with the vendor files of the Go data collector, and create the secret based on the configuration package.

Procedure

  1. Update the Go application by importing the Go data collector module in the application main file.

    import (
        _ "github.ibm.com/APM/godc"
    )
    
  2. Rebuild the Go application with vendor files of the Go data collector.

    1. Extract the Go data collector package file go_datacollector.tgz:

      tar xzf go_datacollector.tgz
      
    2. Merge the vendor files with the vendor files of the application.

    3. Build the application with new vendor files.

      go build -mod=vendor
      
    4. Create the Kubernetes secret based on the configuration package. 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=ibm-cloud-apm-dc-configpack/keyfiles/keyfile.jks \
       --from-file=ibm-cloud-apm-dc-configpack/keyfiles/keyfile.p12 \
       --from-file=ibm-cloud-apm-dc-configpack/keyfiles/keyfile.kdb \
       --from-file=ibm-cloud-apm-dc-configpack/keyfiles/ca.pem \
       --from-file=ibm-cloud-apm-dc-configpack/keyfiles/cert.pem \
       --from-file=ibm-cloud-apm-dc-configpack/keyfiles/key.pem \
       --from-file=ibm-cloud-apm-dc-configpack/global.environment
      
  3. Update the application yaml file to mount the secret. See the following example.

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: MyGoApp
      labels:
        app: MyGoApp
    spec:
      selector:
        matchLabels:
          app: MyGoApp
          pod: MyGoApp
      replicas: 1
      template:
        metadata:
          name: MyGoApp
          labels:
            app: MyGoApp
            pod: MyGoApp
        spec:
          containers:
          - name: MyGoApp
            image: mycluster.icp:8500/default/MyGoApp:v1
            imagePullPolicy: Always
            ports:
            - containerPort: 3000
              protocol: TCP
            env:
            - name: APPLICATION_NAME
              value: "MyGoApp"
            volumeMounts:
            - name: global-environment
              mountPath: /opt/ibm/apm/serverconfig
          volumes:
          - name: global-environment
            secret:
              secretName: icam-server-secret 
              optional: true
    
  4. Redeploy the Go application.