Setting up mackerel-container-agent in Kubernetes

This document details the setup process of mackerel-container-agent for Kubernetes.

Operation conditions

The --read-only-port option for kubelet running on Worker Node must be enabled (enabled by default). Note that if --read-only-port=0 is specified, it will be invalid.

Adding the container to the Pod Template

Specify the mackerel-container-agent container in the Pod Template that you would like to monitor.

Item Value
name mackerel-container-agent
image mackerel/mackerel-container-agent:latest
imagePullPolicy Always
resources.limits.memory 128Mi
env See below

Environment variable configurations

Definitions for environment variables are required with mackerel-container-agent.

  • MACKEREL_CONTAINER_PLATFORM: kubernetes
  • MACKEREL_APIKEY: Mackerel API key
  • MACKEREL_KUBERNETES_KUBELET_HOST:
valueFrom:
  fieldRef:
    fieldPath: status.hostIP
  • MACKEREL_KUBERNETES_NAMESPACE:
valueFrom:
  fieldRef:
    fieldPath: metadata.namespace
  • MACKEREL_KUBERNETES_POD_NAME:
valueFrom:
  fieldRef:
    fieldPath: metadata.name

The following items are configured arbitrarily.

  • MACKEREL_KUBERNETES_KUBELET_READ_ONLY_PORT: Port number
    • When changing the port number by specifying the --read-only-port flag in kubelet (Default: 10255)
    • Setting 0 will stop the use of the kubelet read-only port
  • MACKEREL_KUBERNETES_KUBELET_PORT: Port number
    • When changing the port number by specifying the --port flag in kubelet (Default: 10250)

Manifest example

apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  containers:
  # ...
  - name: mackerel-container-agent
    image: mackerel/mackerel-container-agent:latest
    imagePullPolicy: Always
    resources:
      limits:
        memory: 128Mi
    env:
      - name: MACKEREL_CONTAINER_PLATFORM
        value: kubernetes
      - name: MACKEREL_APIKEY
        value: <Mackerel APIKey>
      - name: MACKEREL_KUBERNETES_KUBELET_HOST
        valueFrom:
          fieldRef:
            fieldPath: status.hostIP
      - name: MACKEREL_KUBERNETES_NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: MACKEREL_KUBERNETES_POD_NAME
        valueFrom:
         fieldRef:
            fieldPath: metadata.name

When using roles or plugins, refer to the "Agent configurations" here.

Start monitoring

Deploy the mackerel-container-agent added manifest and start Pod monitoring.

If this does not work, please refer to the Pod log.