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.

Deploying Metrics Server

  1. Run the following command to start the metrics server.

On Kubernetes v1.21+:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability-1.21+.yaml

On Kubernetes v1.19-1.21:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability.yaml
  1. To disable tls for the metrics server, edit the deployment file and add the following line under container args.
---kubelet-insecure-tls=true
  1. Save and exit.

Verify if the metrics server is deployed successfully

Check if pods are ready and running

NAMESPACE NAME READY STATUS RESTARTS AGE
metrics-server metrics-server-57dddcd97f-bnq49 1/1 Running 0 26h
metrics-server metrics-server-57dddcd97f-z9hff 1/1 Running 0 26h

SixthSense Kubernetes Agent

Deploying the agent

  1. Download the Docker image

The onboarding team will provide the credentials to log in to the registry and the latest agent version.

docker login gitlab-registry.34.120.183.186.sslip.io
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: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: k8s-agent-cluster-role
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- nonResourceURLs:
- '*'
verbs:
- get
- watch
- list
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: sixthsense-k8s-agent
name: sixthsense-k8s-agent
namespace: sixthsense-k8s-agent
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: k8s-agent-cluster-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: k8s-agent-cluster-role
subjects:
- kind: ServiceAccount
name: sixthsense-k8s-agent
namespace: sixthsense-k8s-agent

Run the following command.

kubectl apply -f sixthsense-clusterrole.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
namespace: sixthsense-k8s-agent
spec:
replicas: 1
selector:
matchLabels:
app: sixthsense-k8s-agent
template:
metadata:
labels:
app: sixthsense-k8s-agent
spec:
containers:
- image: <sixthsense_agent_image>
name: sixthsense-kubernetes-agent
env:
- name: SS_AUTHENTICATION
value: <Auth_Token>
- name: SS_METRIC_URL
value: http://kube-state-metrics.kube-system.svc.cluster.local:8080/metrics #8081 & 8080 DEBUG
- name: SS_CADVISOR_URL
value: ""
- name: SS_LOGGING
value: debug
- name: SS_SERVICE_NAME
value: <name of the service>
- name: SS_SECURE
value: "false"
- name: SS_BACKEND
value: <Backend_URL>
- name: SS_DEVELOPMENT
value: "false"
- name: SS_NAMESPACES
value: kube-system #List of all namespaces to monitor
- name: SS_RESTART_MEMORY_LIMIT
value: "500"
- name: SS_RESTART_DURATION
value: "12"
resources:
requests:
memory: "500Mi"
cpu: "750m"
limits:
memory: "1Gi"
cpu: "1"
serviceAccount: sixthsense-k8s-agent
serviceAccountName: sixthsense-k8s-agent

Run the following command.

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