Before you install vRealize Operations Management Pack for Kubernetes, you must deploy the cAdvisor DaemonSet on the cluster. Based on the Kubernetes settings, you must create a cAdvisor YAML definition.

Here are a few points to consider when you create a cAdvisor YAML definition:

  • Containers running on hostPort must be accessible on your cluster. For example, the sample YAML definition on hostPort given below has port 31194 as the hostPort. So, the cluster must allow a connection on port 31194.

    If the containers running on hostPort are not accessible, verify with hostNetwork. A sample YAML definition on hostNetwork specific to Tanzu Kubernetes Grid Integrated (TKGI) is provided in Sample cAdvisor YAML Definition on HostNetwork.

  • The docker path configured in the volume must be correct.

    Note:

    The docker path can be different based on your settings.

  • All the nodes must have sufficient CPU and memory to run DaemonSets.

  • You must use the hostPort defined in the YAML definition as the cAdvisor port when you create an adapter instance.

Sample cAdvisor YAML Definition on HostPort

apiVersion: apps/v1 # apps/v1beta2 in Kube 1.8, extensions/v1beta1 in Kube < 1.8
kind: DaemonSet
metadata:
  name: vrops-cadvisor
  namespace: kube-system 
  labels:
    app: vrops-cadvisor
  annotations:
      seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
spec:
  selector:
    matchLabels:
      app: vrops-cadvisor
  template:
    metadata:
      labels:
        app: vrops-cadvisor
        version: v0.33.0
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: vrops-cadvisor
        image: google/cadvisor:v0.33.0
        resources:
          requests:
            memory: 250Mi
            cpu: 250m
          limits:
            cpu: 400m
        volumeMounts:
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: var-run
          mountPath: /var/run
          readOnly: true
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: docker
          mountPath: /var/lib/docker  #Mouting Docker volume  
          readOnly: true
        - name: disk
          mountPath: /dev/disk
          readOnly: true
        ports:
          - name: http
            containerPort: 8080 #Port exposed 
            hostPort : 31194 #Host's port - Port to expose your cAdvisor DaemonSet on each node
            protocol: TCP
      automountServiceAccountToken: false
      terminationGracePeriodSeconds: 30
      volumes:
      - name: rootfs
        hostPath:
          path: /
      - name: var-run
        hostPath:
          path: /var/run
      - name: sys
        hostPath:
          path: /sys
      - name: docker
        hostPath:
          path: /var/lib/docker #Docker path in Host System
      - name: disk
        hostPath:
          path: /dev/disk

Sample cAdvisor YAML Definition on HostNetwork

apiVersion: apps/v1 # apps/v1beta2 in Kube 1.8, extensions/v1beta1 in Kube < 1.8
kind: DaemonSet
metadata:
  name: vrops-cadvisor
  namespace: kube-system
  labels:
    app: vrops-cadvisor
spec:
  selector:
    matchLabels:
      name: vrops-cadvisor
  template:
    metadata:
      labels:
        name: vrops-cadvisor
        version: v0.33.0
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      hostNetwork: true
      containers:
      - name: vrops-cadvisor
        image: google/cadvisor:v0.33.0
        imagePullPolicy: Always
        volumeMounts:
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: var-run
          mountPath: /var/run
          readOnly: false
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: docker
          mountPath: /var/lib/docker #Mouting Docker volume
          readOnly: true
        - name: docker-sock
          mountPath: /var/run/docker.sock
          readOnly: true
        - name: containerd-sock
          mountPath: /var/run/containerd.sock
          readOnly: true
        - name: disk
          mountPath: /dev/disk
          readOnly: true
        ports:
        - name: http
          containerPort: 31194 #Port exposed
          hostPort: 31194  #Host's port - Port to expose your cAdvisor DaemonSet on each node
          protocol: TCP
        securityContext:
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        args:
          - --port=31194
          - --profiling
          - --housekeeping_interval=1s
      terminationGracePeriodSeconds: 30
      volumes:
      - name: rootfs
        hostPath:
          path: /
      - name: var-run
        hostPath:
          path: /var/run
      - name: sys
        hostPath:
          path: /sys
      - name: docker
        hostPath:
          path: /var/vcap/store/docker/docker #Docker path in Host System
      - name: docker-sock  
        hostPath:
          path: /var/vcap/sys/run/docker/docker.sock
      - name: containerd-sock
        hostPath:
          path: /var/run/docker/containerd/docker-containerd.sock
      - name: disk
        hostPath:
          path: /dev/disk

Sample Deployment of cAdvisor as a DaemonSet

In this example, the deployment of cAdvisor as a DaemonSet is performed on a Kubernetes cluster that is ready and running.

  1. Deploy a cluster. Here the name of the cluster can be cluster-01.

  2. Create a vrops-cAdvisor.yaml file on this cluster and run it as a DaemonSet using the commandkubectl config use-context tkg-cluster-03-admin@tkg-cluster-03.

  3. Switch to Temp directory using the command root@tkg [~]tkg-cluster-03-admin@tkg-cluster-03:default)# cd /tmp.

  4. Create a a YAML file named vrops-cAdvisor.yaml using vi command root@tkg [~]tkg-cluster-03-admin@tkg-cluster-03:default)# vi vrops-cAdvisor.yaml.

  5. Run kubectl apply -f vrops-cAdvisor.yaml to run cAdvisor as a Daemonset.

  6. Run less .kube/config to read the configuration file and note down the IP address and credentials to add to vRealize Operations.