Monitoring Kubernetes with AppOptics

AppOptics provides both monitoring for Kubernetes as a cluster, as well as the containers and processes running inside it. Monitoring applications running in Kubernetes is done via our APM agents. To learn more about Kubernetes plugin please see its documentation.

Setup

There are 3 basic ways to monitor a Kubernetes cluster with AppOptics: as a pod, “bare-metal” on the Kubernetes master, and as a sidecar.

Pod setup

In this setup, the SolarWinds Snap Agent is running in a Kubernetes pod.

  • First, you’ll need to set up Kubernetes service authentication. To create an SolarWinds service account in the Kubernetes cluster:

    $ git clone https://github.com/solarwinds/solarwinds-snap-agent-docker
    $ cd solarwinds-snap-agent-docker
    $ kubectl create -f swisnap-agent-serviceaccount.yaml
    

    (See solarwinds-snap-agent-docker for more details.)

  • Next, use the deployment manifest defined in solarwinds-snap-agent-docker:

    • Update the manifest to contain your SOLARWINDS_TOKEN
    • In the env section of swisnap-agent-k8s deployment, you can configure which plugins should be run by setting SWISNAP_ENABLE_<plugin_name> to either true or false. Plugins turned on via environment variables are using default configuration and taskfiles.
  • After configuring deployment to your needs (please refer to Integrating AppOptics Plugins with Kubernetes), type and run following command:

    $ kubectl create -f swisnap-agent-deployment.yaml
    
  • Finally, check if the deployment is running properly:

    $ kubectl get deployment swisnap-agent-k8s
    

“Bare-metal” setup

In this setup, the SolarWinds Snap Agent is running on the Kubernetes master.

  • First, the solarwinds user must have access to the kubeconfig.

    • By default, Kubernetes config is stored in /etc/kubernetes/admin.conf
    • Copy the Kubernetes configuration file to destination specified in Kubernetes plugin config and change its owner to solarwinds user
    $ sudo mkdir -p /opt/SolarWinds/Snap/etc/.kube
    $ sudo cp /etc/kubernetes/admin.conf /opt/SolarWinds/Snap/etc/.kube/config
    $ sudo chown -R solarwinds:solarwinds /opt/SolarWinds/Snap/etc/.kube
    
    • Example plugin config:
    collector:
    kubernetes:
        all:
        incluster: false
        kubeconfigpath: "/opt/SolarWinds/Snap/etc/.kube/config"
        interval: 60s
    
    load:
        plugin: snap-plugin-collector-aokubernetes
        task: task-aokubernetes.yaml
    
    • Note: the plugin config must include the incluster: false setting, which denotes that the SolarWinds Snap Agent is not running as pod in Kubernetes cluster
  • You can easily interact with SolarWinds Snap Agent via swinsap CLI. For additional information about swisnap CLI please see Troubleshooting.

    $ swisnap task list
    

Sidecar setup

In this setup, the agent will monitor only services running in particular pod(s), not Kubernetes itself.

  • Useful when you want to monitor only specific per-pod-services
  • Configuration is similar to pod setup
  • In order to monitor specific services only, the kubernetes and aosystem plugins should be disabled by setting SWISNAP_ENABLE_KUBERNETES to false and SWISNAP_DISABLE_HOSTAGENT to true in swisnap-agent-deployment.yaml

Example: Running Apache Server with sidecar SolarWinds Snap Agent

In order to monitor Apache with the agent in a sidecar, Apache pod config should be passed to swisnap-agent-deployment.yaml or vice-versa, e.g. (notice SWISNAP_ENABLE_APACHE):

containers:
- name: apache
    imagePullPolicy: Always
    image: '<your-image>'
    ports:
    - containerPort: 80
- name: swisnap-agent-ds
    image: 'solarwinds/solarwinds-snap-agent-docker:1.0.0'
    imagePullPolicy: Always
    env:
    - name: SOLARWINDS_TOKEN
        value: 'SOLARWINDS_TOKEN'
    - name: APPOPTICS_HOSTNAME
        valueFrom:
        fieldRef:
            fieldPath: spec.nodeName
    - name: SWISNAP_ENABLE_DOCKER
        value: 'false'
    - name: SWISNAP_ENABLE_APACHE
        value: 'true'
    - name: SWISNAP_DISABLE_HOSTAGENT
        value: 'true'
    - name: HOST_PROC
        value: '/host/proc'

In the example above, the sidecar will run only the Apache plugin. Additionally, if the default Apache Plugin configuration is not sufficient, custom one should be passed to pod running SolarWinds Snap Agent - Integrating AppOptics Plugins with Kubernetes.

Note

Containers inside the same pod can communicate through localhost, so there’s no need to pass a static IP - Resource sharing and communication

Integrating AppOptics Plugins with Kubernetes

In case of “bare-metal” setup please follow steps described in Integrations. When SolarWinds Snap Agent is running inside Kubernetes Pod, integrating AppOptics Plugins with Kubernetes requires some additional steps. SolarWinds Snap Agent image is using default plugins configuration files and tasks manifests. In order to use your own configuration you would have to create Kubernetes configMap. In this example we’ll set up two configMaps, first for plugins and second for tasks.

# create plugins configMap
kubectl create configmap plugin-configs --from-file=/path/to/my/plugins.d/ --namespace=kube-system

# create tasks configMap
kubectl create configmap task-manifests --from-file=/path/to/my/tasks.d/ --namespace=kube-system

# check if everything is fine
kubectl describe configmaps plugin-configs task-manifests

ConfigMaps should be attached to SolarWinds Snap Agent deployment. Here’s the example, notice spec.template.spec.containers.volumeMounts and spec.template.spec.volumes:

kind: Deployment
apiVersion: apps/v1beta2
metadata:
  name: swisnap-agent-k8s
  namespace: kube-system
  labels:
    app: swisnap-agent-k8s
spec:
  replicas: 1
  selector:
    matchLabels:
      app: swisnap-agent-k8s
template:
  metadata:
    labels:
      app: swisnap-agent-k8s
  spec:
    serviceAccountName: swisnap-agent-serviceaccount
    containers:
      - name: swisnap-agent-k8s
        image: 'solarwinds/solarwinds-snap-agent-docker:1.0.0'
        imagePullPolicy: Always
        volumeMounts:
          - name: plugins-vol
            mountPath: /opt/SolarWinds/Snap/etc/plugins.d
          - name: tasks-vol
            mountPath: /opt/SolarWinds/Snap/etc/tasks.d
        env:
          - name: SOLARWINDS_TOKEN
            value: 'SOLARWINDS_TOKEN'
          - name: SWISNAP_DISABLE_HOSTAGENT
            value: 'true'
        resources:
          limits:
            cpu: 100m
            memory: 512Mi
          requests:
            cpu: 100m
            memory: 256Mi
    volumes:
      - name: plugins-vol
        configMap:
          name: plugin-configs
          items:
            - key: <first-plugin-name>.yaml
              path: <first-plugin-name>.yaml
            - key: <second-plugin-name>.yaml
              path: <second-plugin-name>.yaml
            - key: <third-plugin-name>.yaml
              path: <third-plugin-name>.yaml
      - name: tasks-vol
        configMap:
          name: task-manifests
          items:
            - key: task-ao<first-plugin-name>.yaml
              path: task-ao<first-plugin-name>.yaml
            - key: task-ao<second-plugin-name>.yaml
              path: task-ao<second-plugin-name>.yaml
            - key: task-ao<third-plugin-name>.yaml
              path: task-ao<third-plugin-name>.yaml
strategy:
  type: RollingUpdate
  rollingUpdate:
    maxUnavailable: 0
    maxSurge: 1

When you’re attaching taskfiles and plugin configuration files through configMaps, there’s no need to set environment variables SWISNAP_ENABLE_<plugin-name>. SolarWinds Snap Agent will automatically load plugins based on files stored in configMaps. For further informations please visit solarwinds-snap-agent-docker.

Dashboard

After you’ve successfully set up the SolarWinds Snap Agent, enable the Kubernetes plugin in the AppOptics UI and you should see data pour in. More about Charts and Dashboards.

../../../../_images/kubernetes_dashboard.png