Use Docker Visibility with Red Hat OpenShift

This page describes how to set up the Machine Agent with Docker Visibility enabled to run as a DaemonSet on an OpenShift cluster.

Docker Visibility supports OpenShift Version 3. With the Machine Agent, you can collect performance data from OpenShift clusters. By installing the agent as a DaemonSet on each host in the OpenShift cluster, the DaemonSet monitors each host on the OpenShift cluster and the corresponding containers that have an Splunk AppDynamics App Agent running. This process is similar to that of monitoring the Kubernetes cluster.

CAUTION:

Using Docker Visibility to monitor OpenShift containers is no longer the preferred option and will eventually be deprecated. Use the Cluster Agent instead as described in Monitor Kubernetes with the Cluster Agent. The Cluster Agent supports OpenShift container visibility, as well as visibility into cluster health and capacity.

Before You Begin

Attention: This functionality requires a Server Visibility license.
  • You must have an OpenShift user account with a cluster-admin role, such as system:admin.
  • Install the OpenShift command line tool (oc)
  • We recommend that you use Docker CE/EE v17.03 or Docker Engine >= v1.13 with this product. Some data may be unavailable if you are using previous versions of Docker.

Set the Java Options

By default, the MaxMetaspaceSize is set to 100 MB in OpenShift. If your application operates within a small margin of its existing memory resource allocation, increase the allocation for the application. We recommend allocating additional Metaspace Size space to accommodate the machine agent. Directly configure the environment variable GC_MAX_METASPACE_SIZE to set the MaxMetaspaceSize parameter in the deployment through a config map.

Register the Container ID as the Host ID

Install an App Server Agent in each container in a Kubernetes pod to collect application metrics. If multiple App Server agents are running in the same pod (for example, in the RedHat OpenShift platform), you must register the container ID as the unique host ID on both the App Server Agent and the Machine Agent to collect container-specific metrics from the pod. Kubernetes pods can contain multiple containers and they share the same host ID. The Machine Agent cannot identify different containers running in a pod unless each container ID is registered as the host ID.

To register the container ID as the host ID:

  1. Get the container ID from the cgroup
    cat /proc/self/cgroup | awk -F '/' '{print $NF}'  | head -n 1
  2. Register the App Server Agents.
    .
    -Dappdynamics.agent.uniqueHostId=$(sed -rn '1s#.*/##; 1s/docker-(.{12}).*/\1/p' /proc/self/cgroup) 
  3. Register the Machine Agent.
    -Dappdynamics.docker.container.containerIdAsHostId.enabled=true

プロジェクトおよびサービスアカウントの作成

OpenShift の用語では、プロジェクトはユーザとそのリソースのグループを分離するメカニズムです。管理者は、プロジェクトの作成や特定のプロジェクトの管理に関する権限を持つ個々のユーザまたはグループを指定できます。

マシンエージェントを他のプロジェクトから分離するために、マシン エージェント プロジェクトを作成します。

oc new-project machine-agent

マシンエージェントがメトリックを取得するために必要な権限を持つサービスアカウント を作成するには、次の手順を実行します。

  1. 現在のプロジェクトがマシンエージェントであることを確認します。
    oc status
  2. サービス アカウントを作成します。
    oc create serviceaccount ma
    サービスアカウントは、通常のユーザのクレデンシャルを共有することなく、OpenShift API アクセスを制御する安全な方法を提供します。
  3. サービスアカウントに特権セキュリティコンテキスト制約(SCC)を割り当てます。SCC は、ポッドの権限と能力を決定します。
    oc adm policy add-scc-to-user privileged -z ma
    サービスアカウントの権限の詳細なリストについては、「サービスアカウントのセキュリティ権限」を参照してください。
  4. cluster-reader ロールをサービスアカウントに追加します。
    oc adm policy add-cluster-role-to-user cluster-reader -z ma

マシンエージェントの保護

セキュリティを強化してマシンエージェントを展開できます。プロジェクトのセキュリティレベルを決定し、セキュリティ権限を活用してマシンエージェントを保護します。

cluster-reader ロールを持たないマシンエージェントの実行

cluster-reader ロールを持たない場合、マシンエージェントは OpenShift クラスタからポッドや ReplicaSet などの情報を読み取ることができません。ただし、エージェントはアプリケーション サーバ エージェント コンテナのタグを除き、他のメトリックを収集することもできます。

特権コンテナモードを使用しないマシンエージェントの実行

この権限を無効にするには、次のセクションを DaemonSet YAML ファイルから削除します。

securityContext:
          privileged: true  

特権コンテナモードでないと、マシンエージェントは などのファイルを読み取ることができません。そのため、プロセスやネットワークなどのメトリックを収集できません。

この権限を無効にしても、アプリケーション サーバ エージェントのコンテナメトリックの収集には影響しません。

サービスアカウントのセキュリティ権限

サービスアカウントには、マシンエージェントが実行されているプロジェクトで最大の分離を提供するために、次のセキュリティ権限が必要です。

権限説明
cluster-reader ロール

この cluster-reader ロールを使用すると、マシンエージェントは OpenShift クラスタからタグを読み取ることができます。

例:

oc adm policy add-cluster-role-to-user cluster-reader -z ma
特権 SCC

特権 SCC を使用すると、マシンエージェントをルートユーザとして実行できます。

例:

oc adm policy add-scc-to-user privileged -z ma
特権コンテナとして実行

特権コンテナとして実行すると、マシンエージェントは からのファイルの読み取りや、 からのプロセス情報の読み取りができます。

この権限は、次のように DaemonSet YAML ファイルで設定されます。

securityContext:
privileged: true

Create a Docker Image of the Machine Agent

Copy the following files to a directory on a machine that can build the Docker image.

  • Machine Agent Bundle - 64-bit Linux (zip).

    Download this bundleand rename it to machine-agent.zip.

  • Dockerfile

    See the sample Docker file below.

  • start-appdynamics script

    See thesample script below.

Build the image with your desired method and make it available in your image registry.

Deploy the Machine Agent as DaemonSet

  1. Modify the sample DaemonSet to point to your Controller:
    1. Select the worker node.
      nodeSelector:
      node-role.kubernetes.io/compute: "true"
    2. Change the following Controller information in the sample DaemonSet.
      containers:
      - env:
      - name: APPDYNAMICS_CONTROLLER_HOST_NAME
      value: "<controller-host-name>"
      - name: APPDYNAMICS_CONTROLLER_PORT
      value: "<controller-port>"
      - name: APPDYNAMICS_CONTROLLER_SSL_ENABLED
      value: "true"
      - name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY
      value: "<account-access-key>"
      - name: APPDYNAMICS_AGENT_ACCOUNT_NAME
      value: "<your-account>"
      - name: APPDYNAMICS_SIM_ENABLED
      value: "true"
      - name: APPDYNAMICS_DOCKER_ENABLED
      value: "true"
    3. Specify the Docker image.
      image: "<your image>"
    4. Enable the Machine Agent to run as the privileged user.
      securityContext:
      privileged: true
    5. If you have a different service account name, replace it with the existing one.
      serviceAccount: ma
      serviceAccountName: ma
  2. Create DaemonSet below:
    1. Verify that the current project is machine-agent.
      oc status
    2. Create the machine-agent DaemonSet.
      oc create -f machine-agent-daemonset.yaml

      The Machine Agent appears in the UI.

Verify Machine Agent Status

If the Machine Agent does not appear in the UI, check the status as follows:

  1. Check the machine-agent DaemonSet.
    oc get ds
  2. Check the machine-agent pod.
    oc get pod
    The pod name is machine-agent-daemonset-<XXXX>.
  3. Check logs whether the last line is Started AppDynamics Machine Agent Successfully.
    oc get logs -f <machine-agent-daemonset-<XXXX>>

Sample Machine Agent Deployment Files

Below are sample DaemonSet, Dockerfile and Start Script that you can use as a reference for deploying the Machine Agent.

SampleDaemonSet

Modify the sample DaemonSet to suit your deployment scenario.

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: machine-agent-daemonset
namespace: machine-agent
spec:
selector:
matchLabels:
name: appdynamics-machine-agent
template:
metadata:
labels:
name: appdynamics-machine-agent
spec:
nodeSelector:
node-role.kubernetes.io/compute: "true"
containers:
- env:
- name: APPDYNAMICS_CONTROLLER_HOST_NAME
value: "<your-hostname>"
- name: APPDYNAMICS_CONTROLLER_PORT
value: "<your-port>"
- name: APPDYNAMICS_CONTROLLER_SSL_ENABLED
value: "true"
- name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY
value: "<your-access-key>"
- name: APPDYNAMICS_AGENT_ACCOUNT_NAME
value: "<your-account>"
- name: APPDYNAMICS_SIM_ENABLED
value: "true"
- name: APPDYNAMICS_DOCKER_ENABLED
value: "true"
image: <your-image>
name: machine-agent
securityContext:
privileged: true
volumeMounts:
- mountPath: /hostroot
name: hostroot
readOnly: true
- mountPath: /var/run/docker.sock
name: docker-sock
restartPolicy: Always
imagePullPolicy: Always
serviceAccount: ma
serviceAccountName: ma
volumes:
- name: hostroot
hostPath:
path: /
- name: docker-sock
hostPath:
path: /var/run/docker.sock

Sample Dockerfile

You can use this Dockerfile sample or the one in OpenShift Visibility Manifests.

# Sample Dockerfile for the Machine Agent
# This is provided for illustration purposes only
FROM ubuntu:16.04
# Install required packages
RUN apt-get update && \
apt-get install -y unzip && \
apt-get clean
# Install Machine Agent
ENV MACHINE_AGENT_HOME /opt/appdynamics/machine-agent/
ADD machine-agent.zip /tmp/machine-agent.zip
RUN mkdir -p ${MACHINE_AGENT_HOME}
# Include start script to configure and start MA at runtime
ADD start-appdynamics ${MACHINE_AGENT_HOME}
RUN chmod 774 ${MACHINE_AGENT_HOME}/start-appdynamics
# change files and directories to be owned by root so MA container user in root
group can access
RUN chgrp -R 0 /opt && \
chmod -R g=u /opt
RUN chgrp -R 0 /tmp/machine-agent.zip && \
chmod g=u /tmp/machine-agent.zip
# Changing directory to MACHINE AGENT HOME
WORKDIR ${MACHINE_AGENT_HOME}
# Configure and Run Machine Agent
CMD "./start-appdynamics"

Sample start Script

#!/bin/bash
unzip -oq /tmp/machine-agent.zip -d ${MACHINE_AGENT_HOME} && \
rm /tmp/machine-agent.zip
# Start Machine Agent
./bin/machine-agent -j jre/