Agent

The deployment use the image available on Docker Hub

One agent can effectively monitor multiple PostgreSQL clusters.

You can also use the Agentless approach if you don’t want to install an agent

Create Load Balancer

This example use a service of type LoadBalancer to expose the agent port.

kubectl apply -f https://raw.githubusercontent.com/datasentinel/datasentinel_toolkit/master/docker/agent/kubernetes-loadbalancer.yml

Deploy Agent

This allows the platform to communicate with the agent.

  • Get the external ip of the load balancer

kubectl get services datasentinel-agent  -o jsonpath="{.status.loadBalancer.ingress[0].ip}"
  • Download the definition file

wget https://raw.githubusercontent.com/datasentinel/datasentinel_toolkit/master/docker/agent/kubernetes.yml

You need to replace the DATASENTINEL_AGENT_HOST value by the Load balancer IP

  • Then create the agent

kubectl apply -f kubernetes.yml

A persistent volume datasentinel-agent-config-volume (Mount path /agent/config) is created to store agent configuration files

https://github.com/datasentinel/datasentinel_toolkit/blob/master/docker/agent/kubernetes.yml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: datasentinel-agent
  namespace: default
spec:
  serviceName: datasentinel-agent-service
  selector:
    matchLabels:
      app: datasentinel-agent
  replicas: 1
  template:
    metadata:
      labels:
        app: datasentinel-agent
    spec:
      securityContext:
          fsGroup: 2000
          runAsNonRoot: true
          runAsUser: 1001
      containers:
      - name: datasentinel-agent
        image: datasentinel/datasentinel-agent:latest
        imagePullPolicy: Always
        env:
          - name: DATASENTINEL_AGENT_HOST
            value: LOADBALANCER_IP
          - name: DATASENTINEL_AGENT_PORT
            value: '8384'
        ports:
          - containerPort: 8384
        volumeMounts:
          - name: datasentinel-agent-config-volume
            mountPath: /agent/config
            readOnly: false
  volumeClaimTemplates:
    - metadata:
        name: datasentinel-agent-config-volume
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 1Gi

You can use the agent CLI by attaching a shell: kubectl exec –stdin –tty datasentinel-agent – /bin/bash

// CLI command example
/agent/datasentinel/datasentinel status agent

You can also use the API to configure the agent.

// Check agent status 
curl -k https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/agent/status

Update token with valid license

export TOKEN="Valid license key"

cat <<EOF >body.json
{
    "value" : "$TOKEN"
}
EOF

curl -k --header 'Content-Type: application/json' --request PUT "https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/server/token" -d @body.json

Set Datasentinel upload platform

cat <<EOF >upload_server.json
{
  "host": "datasentinel_server",
  "port": 443
}
EOF

curl -k --header "api-token: $TOKEN" --header 'Content-Type: application/json' -X PUT https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/server -d @upload_server.json
# Check upload server
curl -k -X GET https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/server

Test the communication between the agent and the platform

curl -k --header "api-token: $TOKEN" --request POST https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/server/test-upload

Add a PostgreSQL connection

cat > body.json <<EOF
{
  "host": "172.16.250.199",
  "port": 5432,
  "user": "datasentinel",
  "password": "myPassword",
  "tags": "application=application_name,environment=docker,datacenter=datacenter"
}
EOF

curl -k --header "api-token: $TOKEN" --header 'Content-Type: application/json' --request POST "https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/connections/pg_docker_example" -d @body.json

Check connection

curl -k --header "api-token: $TOKEN" -X GET https://${DATASENTINEL_AGENT_HOST}:${DATASENTINEL_AGENT_PORT}/api/connections

Last updated