Overview
The metrics-server integration allows vCluster to proxy metrics API requests from the virtual cluster to the host cluster’s metrics-server installation. This enables Kubernetes resource metrics (CPU and memory) for pods and nodes without deploying a separate metrics-server in each virtual cluster.Key Benefits:
- Reuse host cluster’s metrics-server installation
- Enable
kubectl top podsandkubectl top nodesin virtual clusters - Support Horizontal Pod Autoscaler (HPA) in virtual clusters
- Reduce resource overhead by sharing metrics infrastructure
How It Works
The integration operates as an API proxy that:- Intercepts metrics API requests from the virtual cluster’s API server
- Translates resource names between virtual and host cluster namespaces
- Proxies requests to the host cluster’s metrics-server
- Filters and transforms responses to show only relevant metrics
- Returns translated metrics to the virtual cluster
9001 within the vCluster control plane and registers the metrics.k8s.io/v1beta1 API service.
Proxied API Endpoints
The integration proxies these metrics API endpoints: Pod Metrics:GET /apis/metrics.k8s.io/v1beta1/pods- List pod metrics across all namespacesGET /apis/metrics.k8s.io/v1beta1/namespaces/{namespace}/pods- List pod metrics in a namespaceGET /apis/metrics.k8s.io/v1beta1/namespaces/{namespace}/pods/{name}- Get specific pod metrics
GET /apis/metrics.k8s.io/v1beta1/nodes- List node metricsGET /apis/metrics.k8s.io/v1beta1/nodes/{name}- Get specific node metrics
Prerequisites
-
metrics-server must be installed on the host cluster
-
Verify metrics-server is running
-
Test metrics on the host cluster
Setup Instructions
Basic Configuration
Enable the metrics-server integration:values.yaml
Advanced Configuration
Customize which metrics APIs to proxy:values.yaml
values.yaml
Disabling Built-in Metrics Server
If you’re using the integration, disable the built-in metrics-server deployment:values.yaml
Usage Examples
View Pod Resource Usage
Once the integration is enabled, use standard kubectl commands:View Node Resource Usage
View metrics for nodes visible in your virtual cluster:Node metrics are only available for nodes that are synced to your virtual cluster. If you’re using fake nodes (default), node metrics will show only synced nodes.
Configure Horizontal Pod Autoscaler
Use HPA with CPU or memory metrics:hpa.yaml
Monitor HPA Scaling Decisions
Using with Vertical Pod Autoscaler
The metrics-server integration also supports VPA:vpa.yaml
Validation
1. Verify API Service Registration
2. Test Metrics API Directly
3. Check vCluster Logs
4. Verify HPA Functionality
Create a test HPA and verify it can read metrics:Common Issues and Solutions
Issue: “metrics not available” Error
Symptoms:kubectl top returns “metrics not available”
Solution:
-
Verify metrics-server is running on the host:
-
Check if the integration is enabled:
-
Restart the vCluster control plane:
Issue: Node Metrics Not Available
Symptoms:kubectl top nodes shows no nodes or wrong nodes
Solution:
Node metrics require node syncing to be enabled:
Issue: HPA Shows “unknown” for Metrics
Symptoms: HPA displays<unknown> for current metrics
Solution:
-
Ensure pods have resource requests defined:
- Wait 1-2 minutes for metrics to populate
-
Check pod metrics are available:
Issue: Metrics API Service Not Found
Symptoms:kubectl get apiservices doesn’t show metrics.k8s.io
Solution:
The API service is registered when vCluster starts. Check the logs:
Issue: Incorrect Metrics Values
Symptoms: Metrics show values from host cluster pods Solution: This indicates a syncing issue. Verify pod syncing is working:Issue: Permission Denied Errors
Symptoms: Metrics API returns 403 Forbidden Solution: Check RBAC permissions for the vCluster service account:Performance Considerations
-
Metrics Scraping Frequency
- The host metrics-server typically scrapes every 15-60 seconds
- Virtual cluster queries are served from cached data
- No additional load on container runtime
-
Label Translation Overhead
- The proxy translates pod/node labels on each request
- Minimal performance impact for typical workloads
- Use label selectors to reduce response sizes
-
API Service Proxy
- Adds ~5-10ms latency for metrics queries
- No impact on pod scheduling or execution
- Suitable for HPA and monitoring use cases
Configuration Reference
Complete configuration options fromchart/values.yaml:897-904:
pkg/integrations/metricsserver/metricsserver.go
Best Practices
-
Always Define Resource Requests
- Set CPU and memory requests for all pods
- Required for HPA to function correctly
- Helps with better resource utilization
-
Use Appropriate HPA Thresholds
- Start with conservative targets (70-80% CPU)
- Monitor actual usage patterns
- Adjust based on application behavior
-
Monitor Metrics Availability
- Set up alerts for metrics API failures
- Check metrics-server health on host cluster
- Test metrics after vCluster upgrades
-
Combine with Custom Metrics
- Use metrics-server for resource metrics
- Add Prometheus adapter for custom metrics
- Implement comprehensive autoscaling strategies
-
Regular Testing
- Verify
kubectl topworks after deployments - Test HPA scaling under load
- Validate metrics during cluster upgrades
- Verify
Comparison with Deployed Metrics Server
| Feature | Integration | Deployed |
|---|---|---|
| Resource overhead | Minimal | ~50-100Mi per vCluster |
| Configuration | Simple | Requires deployment |
| Updates | Automatic with host | Manual per vCluster |
| Latency | +5-10ms | Direct |
| Isolation | Shared | Dedicated |
| Best for | Most use cases | Private nodes mode |