1 Answer
- Newest
- Most votes
- Most comments
0
Yes, you can use the Prometheus-Adapter to autoscale your EKS pods based on the number of active websocket connections.
Here is an example of how you can set it up:
- First, you need to deploy the Prometheus-Adapter in your EKS cluster. You can use the following command to deploy it:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/prometheus-adapter/master/deploy/manifests/prometheus-adapter.yaml
- Next, you need to create a Custom Metrics API server. You can use the following YAML configuration to create a Custom Metrics API server:
apiVersion: v1
kind: ServiceAccount
metadata:
name: custom-metrics
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: custom-metrics
rules:
- apiGroups: ["custom.metrics.k8s.io"]
resources: ["*"]
verbs: ["*"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: custom-metrics
subjects:
- kind: ServiceAccount
name: custom-metrics
namespace: kube-system
roleRef:
kind: ClusterRole
name: custom-metrics
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-metrics
namespace: kube-system
labels:
k8s-app: custom-metrics
spec:
replicas: 1
selector:
matchLabels:
k8s-app: custom-metrics
template:
metadata:
labels:
k8s-app: custom-metrics
spec:
serviceAccountName: custom-metrics
containers:
- image: k8s.gcr.io/custom-metrics-stackdriver-adapter:v0.10.0
name: custom-metrics-adapter
args:
- --source=stackdriver
- --stackdriver.metrics-prefix=custom.googleapis.com/
- --config=/etc/config/config.yaml
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: custom-metrics-config
- Create a configuration file for the Prometheus-Adapter. Here is an example configuration file that retrieves the number of active websocket connections:
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-adapter-config
namespace: kube-system
data:
metrics:
- seriesQuery: 'websocket_connections{job="your-app"}'
resources:
overrides:
resource: 'pod'
name:
matches: "websocket_connections"
as: "websocket_connections"
metricsQuery: 'max_over_time({{{.Series}}}[5m])'
- Finally, you can create a Horizontal Pod Autoscaler (HPA) using the following command:
kubectl autoscale deployment your-app --cpu-percent=50 --min=1 --max=10 --name=your-app-hpa
This HPA will scale up or down based on the number of active websocket connections.
You can also use the **kubectl get hpa **command to check the status of the HPA and see how many replicas are currently running.
I hope this helps! Let me know if you have any questions.
answered a year ago
Relevant content
- asked 8 months ago
- Accepted Answerasked 2 years ago
- asked 2 years ago
- asked 2 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 3 months ago