Apart from infrastructure metrics like CPU, memory, disk IO, etc., applications generate metrics based on their app logic. For example, DB applications can have several queries, several pending transactions, and so on; message broker applications can have several topics, several messages not delivered, and so on. These metrics are essential in debugging and finding out root-causing issues.
Kubernetes 2.0 provides a mechanism to display both application/workload metrics and the infrastructure metrics of pods.
ConfigMap
All workload ConfigMaps share a consistent syntax. Below is a detailed explanation of user configurations, such as targetPodSelector, auth, and more. Additionally, an example is provided to demonstrate how workloads can be defined in the opsramp-workload-metric-user-config
ConfigMap.
Sample ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: opsramp-workload-metric-user-config
namespace: opsramp-agent
data:
workloads: |
mysql:
- name: mysql1
collectionFrequency: 1m
auth: credentials
userName:
source: value
value: root
password:
source: value
value: password
targetPodSelector:
matchLabels:
- key: app.kubernetes.io/name
operator: ==
value:
- mysql
Field Descriptions
Field | Type | Description |
---|---|---|
mysql | Object | Name of the workload/application. |
name | String | Unique name for the MySQL configuration. |
collectionFrequency | String | Collection frequency (e.g., 10s, 30m, 1h). Default value is 1m. |
auth | String | Authentication method (options: none, credentials, tls). |
userName | - | Username used for authentication. |
password | - | Password used for authentication. |
port | Integer | Port number where metrics are exposed for the workload. |
targetPodSelector | Object | Criteria to select target pods. All specified conditions must match to select a pod. |
matchLabels | Array | Specifies matching criteria for pod labels. |
key | String | Pod label key. |
operator | String | Operator to compare the key (options: ==, !=, =, in, notin, exists, !exists). |
value | Array | Pod label values as an array of strings. |
Common Configuration for All Workloads
This is a common configuration settings that apply to all workloads.
userName:
source: configmap
value: default/nginx-cm/user
password:
source: secret
value: default/nginx-secret/password
End-to-End Guide: Monitoring a Redis Instance in Kubernetes 2.0
This example demonstrates how to monitor a Redis application instance running in a Kubernetes 2.0 cluster using a ConfigMap. The provided ConfigMap supports multiple authentication methods for seamless integration.
Step 1: Retrieve the ConfigMap
To check the existing workload configuration, use the following command:
kubectl get configmap workload-master -n <agent-installed-namespace>
Step 2: Create the ConfigMap
If this is your first time setting up workload monitoring, create a new ConfigMap named workload-master
in the <agent-installed-namespace
>. Use the following manifest as a template:
apiVersion: v1
kind: ConfigMap
metadata:
name: workload-master
namespace: opsramp-agent
data:
workloads: |
redis:
- name: redis
auth: none
port: 6379
collectionFrequency: 2m
targetPodSelector:
matchLabels:
- key: app
operator: ==
value:
- redis
- name: redis-with-tls
auth: tls
certFile:
source: secret
value: default/redis-tls-client/redis-client.crt
keyFile:
source: secret
value: default/redis-tls-client/redis-client.key
port: 6379
collectionFrequency: 2m
targetPodSelector:
matchLabels:
- key: app
operator: ==
value:
- redis-tls
- name: redis-with-credentials
auth: credentials
userName:
source: value
value: sri
password:
source: configmap
value: default/redis-config/REDIS_PASSWORD
port: 6379
collectionFrequency: 2m
targetPodSelector:
matchLabels:
- key: app
operator: ==
value:
- redis-creds
Step 3: Apply the ConfigMap
Once you have created or updated the manifest with all desired workloads, apply it using the following command:
kubectl apply -f <path-to-your-manifest-file>
Step 4: View Metrics in OpsRamp Portal
After a few minutes, you will be able to see the metrics in the OpsRamp portal under Dashboards > Dashboard.
Step 5: Create Alerts and Availability Rules
With metrics flowing into the OpsRamp portal, you can create alerts and availability rules based on these workload or application-specific metrics by editing the respective K8s ConfigMaps. This version provides clear steps and maintains a logical flow, making it easy for users to follow along.
The configuration of the Redis application has been successfully completed, and you can now monitor the Redis instances effectively.
You can monitor other application instances within a Kubernetes 2.0 cluster by utilizing a ConfigMap. Refer to the next page for the list of supported applications.