-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhpa.txt
More file actions
84 lines (51 loc) · 3.34 KB
/
hpa.txt
File metadata and controls
84 lines (51 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Install the metrics server
1. The Kubernetes metrics server is an aggregator of resource usage data in your cluster.
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Yes, to enable Horizontal Pod Autoscaling (HPA) with custom metrics in Kubernetes, you need to have the Metrics Server installed in your cluster.
The Metrics Server is a component that collects resource utilization data (such as CPU and memory) from the cluster's nodes and provides
it as metrics to other Kubernetes components, including the Horizontal Pod Autoscaler.
Here's how you can install the Metrics Server in your Kubernetes cluster:
Step 1: Download the Metrics Server manifest
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Step 2: Modify the Metrics Server manifest
Open the downloaded `components.yaml` file and find the `metrics-server` Deployment definition. Add the following flags under the `containers` section of the Deployment:
yaml
args:
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalIP
- --kubelet-use-node-status-port
This configuration allows the Metrics Server to connect securely with the Kubernetes API server and fetch the necessary metrics.
Step 3: Deploy the Metrics Server
Apply the modified `components.yaml` file to deploy the Metrics Server in your cluster:
kubectl apply -f components.yaml
Step 4: Verify the Metrics Server deployment
Check if the Metrics Server components are running:
kubectl get deployment metrics-server -n kube-system
kubectl get pods -n kube-system | grep metrics-server
Once the Metrics Server is running, it starts collecting metrics from the cluster nodes. The Horizontal Pod Autoscaler can then utilize these metrics to make scaling decisions based on resource utilization.
After installing the Metrics Server, you can proceed with creating HPA objects that use custom metrics to scale your applications.
Note: The above steps assume you have the necessary permissions to deploy resources in the cluster. If you encounter any issues during the installation or verification process, please ensure you have the appropriate permissions or consult with your cluster administrator.
Let me know if you need any further assistance!
Create a simple Apache webserver application with the following command.
kubectl run httpd --image=httpd --requests=cpu=100m --limits=cpu=200m
We can run it as a comment
kubectl autoscale deployment httpd --cpu-percent=50 --min=1 --max=10
Create a hpa.yaml file.
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: httpd
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: hppd
targetCPUUtilizationPercentage: 50
Describe the autoscaler with the following command to view its details.
kubectl describe hpa/httpd
Create a load for the webserver. The following command uses the Apache Bench program to send hundreds of thousands of requests to the httpd server
kubectl run apache-bench -i --tty --rm --image=httpd -- ab -n 500000
Watch the httpd deployment scale out while the load is generated. To watch the deployment and the autoscaler, periodically run the following command.
kubectl get horizontalpodautoscaler.autoscaling/httpd