Installing agents

Kube State Metrics

Kube-state-metrics (KSM) is a simple service that listens to the Kubernetes API server and generates metrics about the state of the objects. The metrics are exported on the HTTP endpoint /metrics on the listening port (default 8080).

Deploying KSM

  1. Clone the repo: https://github.com/kubernetes/kube-state-metrics
  2. Use the following command.
kubectl apply -f examples/standard

Verifying if KSM is deployed successfully

  1. Check the service.
kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-state-metrics ClusterIP None <none> 8080/TCP,8081/TCP 17d
  1. Check the pod.
kubectl get po -n kube-system
NAME READY STATUS RESTARTS AGE
kube-state-metrics-74c958c8bc-cwzzz 1/1 Running 0 17d

If both service and pods are created, KSM is deployed successfully.

cAdvisor

cAdvisor (Container Advisor) provides container users with an understanding of the resource usage and performance characteristics of their running containers. It is a running daemon that collects, aggregates, processes, and exports information about running containers. It has a UI and the metrics are exported on the HTTP endpoint/metrics on the listening port (default 8080). Also, cAdvisor uses Kustomize to manage kubernetes yaml files.

Deploying cAdvisor

  1. Clone the repo: https://github.com/google/cadvisor
  2. Use the following command.
kubectl kustomize deploy/kubernetes/base | kubectl apply -f -

Create a kubernetes service object for cadvisor in cadvisor namespace and map it to the 8080 port of the container.

kubectl apply -f svc.yaml -n cadvisor

Example: Sample file for cadvisor-svc.yaml:

apiVersion: v1
kind: Service
metadata:
labels:
app: cadvisor
name: cadvisor-svc
namespace: cadvisor
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: cadvisor

Verify if cAdvisor is deployed successfully

  1. Check the service.
kubectl get svc -n cadvisor
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cadvisor ClusterIP 10.96.213.4 <none> 8080/TCP 17d
  1. Check the pod.
kubectl get po -n cadvisor
NAME READY STATUS RESTARTS AGE
cadvisor-2mk5s 1/1 Running 0 17d

If both service and pods are created, cAdvisor is deployed successfully.

SixthSense Kubernetes Agent

Deploying the agent

  1. Download the Docker image
  • docker login gitlab-registry.34.120.183.186.sslip.io
  • username & password: (create new read only user for tenant, and share credentials)
  • latest version: latest
  • docker pull gitlab-registry.34.120.183.186.sslip.io/sixthsense/sixthsense-mvn-dependency/sixthsense-kubernetes-agent:agent-version
note

If the instances are behind corporate proxy, Docker pull will not work. Corporate proxy information must be set in Docker config in the URL -- https://docs.docker.com/network/proxy/#configure-the-docker-client.

  1. Create a clusterrole and clusterrolebinding in order to allow agent to fetch the metrics.

Filename: sixthsense-clusterrole.yml

apiVersion: v1
kind: ServiceAccount
metadata:
name: sixthsense-k8s-agent
namespace: <TO BE UPDATED>
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: sixthsense-k8s-agent
rules:
- apiGroups: [""]
resources: ['pods', 'services']
verbs: ['list']---kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: sixthsense-k8s-agent
subjects:
- kind: ServiceAccount
name: default
namespace: <TO BE UPDATED>
roleRef:
kind: ClusterRole
name: sixthsense-k8s-agent
apiGroup: rbac.authorization.k8s.io
kubectl apply -f sixthsense-k8-deploy.yml
  1. Create a deployment using the Docker image.

Sample Deployment file: Name: sixthsense-k8-deploy.yml

apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: sixthsense-k8s-agent
name: sixthsense-k8s-agent
spec:
replicas: 1
selector:
matchLabels:
app: sixthsense-k8s-agent
template:
metadata:
labels:
app: sixthsense-k8s-agent
spec:
containers:
- image: <Image Name>: < Image Tag>
name: sixthsense-kubernetes-agent
env:
- name: SS_AUTHENTICATION
value: <auth token from dashboard>
- name: SS_METRIC_URL
value: http://kube-state-metrics.kube-system.svc.cluster.local:8080/metrics #8081 & 8080 DEBUG
- name: SS_CADVISOR_URL
value: http://cadvisor-svc.cadvisor.svc.cluster.local:8080/metrics #8081 & 8080 DEBUG
- name: SS_LOGGING
value: debug
- name: SS_SERVICE_NAME
value: <name of the service>
- name: SS_SECURE
value: "true"
- name: SS_BACKEND
value: <backend address>
- name: SS_DEVELOPMENT
value: "false"
resources:
requests:
memory: "500Mi"
cpu: "750m"
limits:
memory: "1Gi"
cpu: "1"
kubectl apply -f sixthsense-k8-deploy.yml
  1. Check the pod status.
kubectl get po -n cadvisor
NAME READY STATUS RESTARTS AGE
sixthsense-k8s-agent-2mk5s43 1/1 Running 0 5m