Kubernetes is a container-orchestration system for automating deployment, scaling, and management of containerized applications. Kubernetes integration monitors the health and performance of your Kubernetes cluster.
You can monitor the following Kubernetes components:
KubeDNS / CoreDNS
Kube Scheduler
Kube Controller
Kube API Server
Kubelet
Kube State (Not installed by default in the K8s Cluster)
Metrics Server (Not installed by default in the K8s Cluster)
With Kubernetes monitoring, you can also monitor Docker containers.
Prerequisites
Install Kube State and Metrics Server manually to fetch and monitor metrics.
Get the latest version of the deployment YAML file and compatibility matrix for Kube State and Metrics Server from GitHub:
Configure Kubernetes before you configure the OpsRamp integration.
Step 1: Prerequisites
Install kube-state metrics.
Use the correct version of kube state YAML for the deployment according to the Kubernetes version of the cluster.
When deployed, set the kube state service Cluster IP with an IP Address. The agent requires the address to fetch the metrics from kube state. If Cluster IP is not set (Shown as NONE) modify the service.yaml file and remove clusterIP: None.
AWS, Google, and on-premise environments do not require any patches to collect the DNS metrics.
Google GKE: Enable RBAC
For a Google GKE environment, you must grant permissions to create roles in Kubernetes.
To grant permission to create roles, execute the following command:
This command binds the clusterrole and cluster-admin to the current user.
Step 4: (Optional) On-Premise: Apply patches
If patching is required on on-premise nodes, do the following:
Create a user account in all nodes of the cluster to collect packages information and install patches.
Execute one of the following scripts on the Kubernetes nodes depending on the operating system used to create the cluster, Ubuntu or CentOS.
Ubuntu script:
Configure()
{
mkdir /opt/opsramp/k8s/patch/{tmp,log} -p > /dev/null 2>&1
useradd opskube -s /bin/bash -d /opt/opsramp/k8s/patch/ > /dev/null 2>&1
usermod -p '$6$dBsN2u5SuC.Niy.C$HxPpbXRZcaQpHui8D3QZshhdJz57xhU1roE12U4KEmlyCNiBNzcGRbrNI7.DREwsf18JUAMT27/VaZmr34Bul.' opskube > /dev/null 2>&1
if [ -d /etc/sudoers.d ]
then
echo "opskube ALL=(ALL) NOPASSWD: /opt/opsramp/k8s/patch/" > /etc/sudoers.d/opskube
chmod 0440 /etc/sudoers.d/opskube
else
sed -i '$ a opskube ALL=(ALL) NOPASSWD: /opt/opsramp/k8s/patch/' /etc/sudoers > /dev/null 2>&1
fi
dpkg -s python-apt | grep Status | grep installed
STATUS1=$?
if [ $STATUS1 -eq 0 ]
then
echo "python-apt already installed! No changes required!"
else
apt-get update > /dev/null 2>&1
apt-get -y install python-apt > /dev/null 2>&1
fi
}
CentOS script:
Configure()
{
mkdir /opt/opsramp/k8s/patch/{tmp,log} -p > /dev/null 2>&1
useradd opskube -s /bin/bash -d /opt/opsramp/k8s/patch/ > /dev/null 2>&1
usermod -p '$6$dBsN2u5SuC.Niy.C$HxPpbXRZcaQpHui8D3QZshhdJz57xhU1roE12U4KEmlyCNiBNzcGRbrNI7.DREwsf18JUAMT27/VaZmr34Bul.' opskube > /dev/null 2>&1
if [ -d /etc/sudoers.d ]
then
echo "opskube ALL=(ALL) NOPASSWD: /opt/opsramp/k8s/patch/" > /etc/sudoers.d/opskube
chmod 0440 /etc/sudoers.d/opskube
else
sed -i '$ a opskube ALL=(ALL) NOPASSWD: /opt/opsramp/k8s/patch/' /etc/sudoers > /dev/null 2>&1
fi
rpm -qa | grep rpm-python
STATUS1=$?
if [ $STATUS1 -eq 0 ]
then
echo "rpm-python already installed! No changes required!"
else
yum -y install rpm-python > /dev/null 2>&1
fi
}
OpsRamp configuration
After you configure Kubernetes, configure the OpsRamp integration.
Step 1: Configuring and installing Kubernetes Integration
From All Clients, select the client.
Go to Setup > Integrations > Integrations.
From Available Integrations, select Compute > Kubernetes and click Install.
Enter the Name for the integration.
Select the Deployment type:
On prem
Cloud (AWS, GKE, and AKS)
Select the Container Engine:
Docker
ContainerD
CRI-O
Click Install.
Step 2: Deploy the agent on a Kubernetes node
On the KUBERNETES INTEGRATION page, download the file to the kube-controller or copy the YAML content and paste it into a new file in kube-controller.(Example file name: opsramp-agent-kubernetes.yaml)
Execute the following command in the kube-controller:
kubectl apply -f opsramp-agent-kubernetes.yaml
Deploy only K8s agent in the node that belongs to the Kubernetes cluster, not the Agent installed using pkg (deb/rpm). If a regular agent (non-containerized agent) is already running in the worker nodes of the Kubernetes cluster, uninstall that agent using the following pkg uninstall command:
dpkg -P opsramp-agent OR rpm -e opsramp-agent
Environment Variables in an agent YAML file
You can adjust some aspects of the agent with variables in the agent YAML file.
You can adjust the following environment variable to change the Log Level of the agent:
- name: LOG_LEVEL
value: "warn"
Worker Agent: This DaemonSet is responsible for collecting System Performance Metrics, Container Metrics (Docker Or ContainerD), Kubelet, and all the container app metrics.
Master Agent: This deployment is responsible for collecting k8s-apiserver, k8s-controller, k8s-scheduler, k8s-kube-state, k8s-metrics-server, k8s-coreDNS / kubeDNS metrics.
Connecting Agents using a proxy
To connect through a proxy in Kubernetes, add the following environment variables to the opsramp-agent-master Deployment and opsramp-agent-worker DaemonSet sections in the agent deployment YAML file.
The PROXY_PASSWORD variable must be encoded in base64.
Step 3: Applying Monitoring Templates and Creating Device Management Policy
Apply the appropriate Kubernetes template on the Integration resource (cluster resource) that is created after the deployment of the agent YAML file. Apply the Kubernetes template only on the Integration resource, not on the worker nodes.
Apply the Docker Host Monitoring template and Kubelet Template on each worker agent created under the Integration resource in the application. Alternatively, you can also create a Device Management Policy to do Step 1 and Step 2.
Step 4: (Optional) Configuring Docker and Kubernetes event
Configure the Docker and Kubernetes events.
Configure Docker Events
Docker events are by default disabled in the agent deployment YAML file. The agent supports the following three docker events by default:
Start
Kill
Oom (Out of Memory)
To enable the Docker events, change the DOCKER_EVENTS environment variable to TRUE.
Disabled by Default
- name: DOCKER_EVENTS
value: "FALSE"
Enabled
- name: DOCKER_EVENTS
value: "TRUE"
For agent versions 8.0.1-1 and above, the Docker events are sent as monitoring alerts. For the older versions of the agent, the Docker events are sent as maintenance alerts to the OpsRamp alert browser.
Configure Kubernetes Events
OpsRamp Agent can forward the Kubernetes events that are generated in the cluster.
By default, this feature is disabled in the agent deployment YAML file. To enable, change the K8S_EVENTS environment variable to TRUE.
Disabled by Default
- name: K8S_EVENTS
value: "FALSE"
Enabled
- name: K8S_EVENTS
value: "TRUE"
By default, the agent forwards all the Kubernetes events without making any updates. To forward only selected events, you must edit the kube events config map in the YAML file.
The events are categorized into the following three types:
Node
Pod
Other
To opt-out of any of these events, remove the event from the agent deployment YAML file.
To add an event that is not supported, add the event (Kube Event Reason) under the appropriate category. If the reason matches with the actual Kubernetes event reason, events are forwarded as alerts.
For agent versions 8.0.1-1 and above, the Kubernetes events are sent as monitoring alerts. For the older versions of agent, the Kubernetes events are sent as maintenance alerts to the OpsRamp alert browser.
By default, all events are converted as Warning alerts.
To forward any events with a different alert state, change the event name followed by alert state (Critical/Warning), as shown below.
Check for more configuration-related information, such as namespace-based filtering on the
kubernetes events filtering
page. This is effective starting with agent version 12.0.1-1.
List of Metrics
View the list of metrics with description applicable to the following monitors:
View the integration, go to Infrastructure > Resources.
Assign monitoring templates to the resource.
Validate that the resource was successfully added to OpsRamp.
FAQs
Will the agents deploy automatically when a new node is attached to the Kubernetes cluster?
Yes, worker agents are deployed using a daemonset. As a result, when a new node is joined/attached to the cluster the worker agent gets automatically deployed.
What happens when the pod having the agent is deleted?
A new pod with the agent is deployed automatically by the Kubernetes scheduler.
Does the failure of an agent in one node affect the agents in other nodes?
No, all agents work independently.
As a result, if one agent is not behaving properly then the impact is limited only to that agent.
What happens if the agent container in the pod crashes or gets deleted?
The agent restarts and the monitoring resumes.
Only in a rare scenario, the metrics for an iteration or two is missed.
Are configuration updates inside the container (by logging into the agent container) applied to the agent?
No, any configuration update inside the agent container does not impact the running agent.
All such configuration updates must be performed using config maps and applied again.
Will I get metrics while the agent is getting updated?
Agent update completes in seconds and when the agents are up with the new version, monitoring starts again and all monitoring frequencies are set accordingly.
Only in a rare scenario, one iteration of monitoring is missed.
What is the default Log Level for agents that are being deployed?
The Default Log Level is Warning.
Can a node have more than one agent installed?
No, only one worker agent is installed per node, and one master agent is installed per cluster on any one of the nodes in the cluster.
Does monitoring stop if the master agent crashes or is deleted?
No, only the kube-apps metrics are stopped. Container metrics sent from workers keep working.