Skip to content

How to deploy the Kubernetes agent

You can use any method you prefer to deploy the Zenoss agent for Kubernetes into a cluster. The following sections demonstrate using the kubectl command and using a Helm chart. Both methods require only the name of the cluster and an authentication key.

Deploy with kubectl

Use this procedure to deploy and manage Zenoss agent for Kubernetes with kubectl. The Zenoss agent for Kubernetes supports Kubernetes 1.8 and all subsequent versions and requires metrics-server.

To perform this procedure, you need an authentication key. Also, the deployment configuration in this procedure assumes that Kubernetes can download images from Docker Hub. If not, download the Zenoss agent for Kubernetes and add it to your local registry.

  1. Configure kubectl to use the correct context.

    kubectl config current-context
    
  2. Optional: Create a secret for the authentication key you are using for the cluster.

    While not required, creating a secret is the most secure way to manage information like authentication keys. Replace MY_API_KEY key with an authentication key:

    kubectl -n kube-system create secret generic zenoss \
      --from-literal=api-key=MY_API_KEY ; history -d $(history 1)
    

    The history command removes the authentication key from your shell history file.

  3. Create a configuration file for the agent.

    Replace MY_CLUSTER_NAME on line 60 with the unique name of the target cluster.

    zenoss-agent-kubernetes.yml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: zenoss-agent-kubernetes
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      labels:
        kubernetes.io/bootstrapping: rbac-defaults
      name: system:zenoss-agent-kubernetes 
    rules:
    - apiGroups: ["metrics.k8s.io"]
      resources: ["nodes", "pods"]
      verbs: ["get", "list", "watch"]
    - apiGroups: [""]
      resources: ["nodes", "namespaces", "pods"]
      verbs: ["get", "list", "watch"]
    - apiGroups: ["extensions", "apps"]
      resources: ["deployments"]
      verbs: ["get", "list", "watch"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: zenoss-agent-kubernetes
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:zenoss-agent-kubernetes
    subjects:
    - kind: ServiceAccount
      name: zenoss-agent-kubernetes
      namespace: kube-system
    ---
    apiVersion: app/v1
    kind: Deployment
    metadata:
      name: zenoss-agent-kubernetes
      namespace: kube-system
      labels:
        app: zenoss-agent-kubernetes
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: zenoss-agent-kubernetes
      template:
        metadata:
          labels:
            task: zenoss-agent-kubernetes
        spec:
          serviceAccountName: zenoss-agent-kubernetes
          containers:
          - name: zenoss-agent-kubernetes
            image: zenoss/zenoss-agent-kubernetes
            env:
            - name: CLUSTER_NAME
              value: MY_CLUSTER_NAME
            - name: ZENOSS_API_KEY
              valueFrom:
                secretKeyRef:
                  name: zenoss
                  key: api-key
    
  4. Apply the deployment.

    kubectl apply -f zenoss-agent-kubernetes.yml
    

Manage the agent

To update the agent, edit its configuration file and then apply the file. Kubernetes applies only the changes.

kubectl apply -f zenoss-agent-kubernetes.yml

To remove the agent and all of its resource, enter the following command:

kubectl delete -f zenoss-agent-kubernetes.yml

Deploy with a Helm chart

Use this procedure to deploy Zenoss agent for Kubernetes with Helm. The Zenoss agent for Kubernetes supports Kubernetes 1.8 and all subsequent versions and requires metrics-server.

To perform this procedure, you need:

Follow these steps:

  1. Add the Zenoss repository that contains the Helm chart for the Zenoss agent for Kubernetes to Helm.

    helm repo add zenoss https://zenoss.github.io/charts/
    
  2. Optional: Review the chart parameters that you can specify during deployment.

  3. Deploy the agent.

    • Replace MY_CHART_NAME with a unique name for the chart
    • Replace MY_CLUSTER_NAME with the unique name of the target cluster
    • Replace MY_API_KEY with an authentication key
    helm install MY_CHART_NAME zenoss-agent-kubernetes \
      --set zenoss.clusterName=MY_CLUSTER_NAME \
      --set zenoss.apiKey=MY_API_KEY ; \
      history -d $(history 1)
    

    The history command removes the authentication key from your shell history file.

For more information about using Helm, refer to the Helm documentation.