Agent Deployment for Kubernetes Env.

Introduction

Cavisson monitoring agent provides user, full-stack visibility into the performance of applications, databases, and micro services within a container environment. There are two agents, one is machine agent and another is application agent. Machine agent is CMON and application agent is ND Agent. Following architecture explains both the agents.

 

Cavisson Machine Agent Pod Deployment Steps

Machine Agent is deployed in the DaemonSet. A user can acquire images of machine agent for use with the Docker Engine from the repository: cavissonagents/cmon:4.1.13 at the Docker Hub.

Command

docker pull cavissonagents/cmon:4.1.13

Following are the steps to deploy machine agent pod as a DaemonSets in Kubernetes environment.

  1. Create a config-map for configuring settings in file env. In machine agent configuration file, specify config map under volume section. A config-map allows a user to decouple configuration artifacts from image content to keep containerized applications portable.

Below is the content of sample config-map:

apiVersion: v1
kind: ConfigMap
metadata:
name: cmon-config
namespace: default
data:
cmon.env: “Tier=<TierName>\nController=<ControllerIP>:<Controller Port>\nJAVA_HOME=<Java Home Path>”

Adding above config map data as a volume creates a file cmon.env where this config map is mounted. Above config map creates cmon.env file with the below sample content:

Tier=My_Tier
Controller=127.0.0.1:7892
JAVA_HOME=/usr/java

  1. Create Pod configuration file and then create a pod with that file. One way to make pod through that file by using kubectl command:

kubectl apply -f <config file>)

Explanation of some part of the machine agent configuration file.

kind: DaemonSet

This key value pair shows that machine agent is configured as a DaemonSets. A DaemonSet ensures that all (or some) nodes run a copy of a pod. As nodes are added to the cluster, pods are added to them. As nodes are removed from the cluster, those pods are garbage collected. Deleting a DaemonSet cleans up the pods it created. It ensure that machine agent pod is created in every new node.

spec:
selector:
   matchLabels:
     name: cmon
template:
   metadata:
     labels:
       name: cmon
       app: cmon
   spec:
     tolerations:
       – key: node-role.kubernetes.io/master
         effect: NoSchedule
     containers:
       – name: cmon
         image: cavissonagents/cmon:4.1.13
         imagePullPolicy: IfNotPresent
         ports:
           – containerPort: 7891
             hostPort: 7891
         resources:
           limits:
             cpu: “500m”
             memory: “700Mi”
           requests:
             cpu: “500m”
             memory: “700Mi”
         volumeMounts:
           – name: varlogs
             mountPath: /var/log
           – name: varlibdockercontainers
             mountPath: /var/lib/docker/containers
             readOnly: true
           – name: hostsys
             mountPath: /host/sys
           – name: hostproc
             mountPath: /host/proc
           – name: varrun
             mountPath: /var/run
           – name: cmon-volume
             mountPath: /opt/cavisson/monitors/sys
     volumes:
       – name: varlogs
         hostPath:
           path: /var/log
       – name: varlibdockercontainers
         hostPath:
           path: /var/lib/docker/containers
       – name: hostsys
         hostPath:
           path: /sys
       – name: hostproc
         hostPath:
           path: /proc
       – name: varrun
         hostPath:
           path: /var/run
       – name: cmon-volume
         configMap:
           name: cmon-config
           defaultMode: 440

Above specifications specifies that the name of the container is cmon.

It uses docker image named cavissonagents/cmon:4.1.13 and imagePullPolicy: IfNotPresent determines that if image is not present on the machine then it will pull the image from the docker hub.

VolumeMounts named cmon-volume is defined as a config map of name cmon-config and default mode of this config map is 440 and user needs to mount this volume to /opt/cavisson/monitors/sys.

Cavisson Application Agent Pod Deployment Steps

Following are the steps to deploy application agent pod in Kubernetes environment.

  1. Get application agent tar file from Cavisson Systems.
  2. Untar application agent in your application docker file (Appendix – Agent docker file)
  3. Create a config-map for configuring settings in file ndsettings.conf. In application configuration file, specify config map under volume section. Below is the content of sample config-map:

apiVersion: v1
kind: ConfigMap
metadata:
name: nd-config
namespace: default
data:
ndsettings.conf: “tier=<TierName>\nndcHost=<Hostname>\nndcPort=<Port>\n”

Adding above config map data as a volume creates a file ndsettings.conf where this config map is mounted. Above config map creates ndsettings.conf file with the below sample content:

tier=Cluster_msp_USC1
ndcHost=10.207.140.11
ndcPort=7892

  1. Application agent (NetDiagnostics directory) mounted as Kubernetes Volumes.
  2. Modify the application’s configuration file with the following application agent ‘s arguments:

<-javaagent:/NDAgentPath/lib/ndmain.jar=time,ndAgentJar=/NDAgentPath/lib/ndagent-with-dep.jar,ndHome=/NDAgentPath>

Example:

apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
   purpose: demonstrate-command
spec:
containers:
– name: command-demo-container
   image: debian
   command: [“/bin/echo”]
   args: [“-c”, “….-Dserver.port=8080 -Xms512m -Xmx512m …
-javaagent:/NDAgentPath/lib/ndmain.jar=time,ndAgentJar=/NDAgentPath/lib/ndagent-with-dep.jar,ndHome=/NDAgentPath …”]
volumes:
configMap:
name: nd-config
defaultMode: 440

  1. Use environment variables defined in the configuration file to start the application.

  2. Start the application.

Appendix – Sample Files

cmon.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: cmon
labels:
   name: cmon
   app: cmon
spec:
selector:
   matchLabels:
     name: cmon
template:
   metadata:
     labels:
       name: cmon
       app: cmon
   spec:
     tolerations:
       – key: node-role.kubernetes.io/master
         effect: NoSchedule
     containers:
       – name: cmon
         image: cavissonagents/cmon:4.1.13
         imagePullPolicy: IfNotPresent
         ports:
           – containerPort: 7891
             hostPort: 7891
         resources:
           limits:
             cpu: “500m”
             memory: “700Mi”
           requests:
             cpu: “500m”
             memory: “700Mi”
         volumeMounts:
           – name: varlogs
             mountPath: /var/log
           – name: varlibdockercontainers
             mountPath: /var/lib/docker/containers
             readOnly: true
           – name: hostsys
             mountPath: /host/sys
           – name: hostproc
             mountPath: /host/proc
           – name: varrun
             mountPath: /var/run
           – name: cmon-volume
             mountPath: /opt/cavisson/monitors/sys
     volumes:
       – name: varlogs
         hostPath:
           path: /var/log
       – name: varlibdockercontainers
         hostPath:
           path: /var/lib/docker/containers
       – name: hostsys
         hostPath:
           path: /sys
       – name: hostproc
         hostPath:
           path: /proc
       – name: varrun
         hostPath:
           path: /var/run
       – name: cmon-volume
         configMap:
           name: cmon-config
           defaultMode: 440

Agent docker file

Append following lines in application docker file :

1 FROM openjdk:8
2 RUN mkdir -p /usr/src
3 RUN mkdir -p /opt/cavisson/netdiagnostics
4 COPY target/spring-boot-web-0.0.2-SNAPSHOT.jar /usr/src/app.jar
5 COPY netdiagnostics.4.1.13.107.tar.gz /opt/cavisson/netdiagnostics
6 RUN tar -xvf     
   /opt/cavisson/netdiagnostics/netdiagnostics.4.1.13.107.tar.gz -C    
   /opt/cavisson/netdiagnostics
7 RUN cat /opt/cavisson/netdiagnostics/etc/version
8 WORKDIR /usr/src