sample hpa

This commit is contained in:
Brian On 2022-01-02 22:35:06 -08:00
parent d2deecefbc
commit 4a930b2843
9 changed files with 167 additions and 11 deletions

View file

@ -0,0 +1,25 @@
sample-app:
kubectl create -n default -f sample-app.deploy.yaml
kubectl create -n default -f sample-app.service.yaml
delete-sample-app:
kubectl delete -n default -f sample-app.deploy.yaml
kubectl delete -n default -f sample-app.service.yaml
monitor:
kubectl create -n default -f service-monitor.yaml
hpa:
kubectl delete -f sample-app.hpa.yaml
kubectl create -f sample-app.hpa.yaml
test:
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/http_requests?selector=app%3Dsample-app"
get-ip:
kubectl get service sample-app -o jsonpath='{ .spec.clusterIP }'
busybox:
# run wget -qO- IP_ADDRESS
kubectl run -it --rm --restart=Never busybox --image=gcr.io/google-containers/busybox sh

View file

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
labels:
app: sample-app
spec:
replicas: 1
selector:
matchLabels:
app: sample-app
template:
metadata:
labels:
app: sample-app
spec:
containers:
- image: luxas/autoscale-demo:v0.1.2
name: metrics-provider
ports:
- name: http
containerPort: 8080

View file

@ -0,0 +1,24 @@
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
name: sample-app
spec:
scaleTargetRef:
# point the HPA at the sample application
# you created above
apiVersion: apps/v1
kind: Deployment
name: sample-app
# autoscale between 1 and 10 replicas
minReplicas: 1
maxReplicas: 10
metrics:
# use a "Pods" metric, which takes the average of the
# given metric across all pods controlled by the autoscaling target
- type: Pods
pods:
# use the metric that you used above: pods/http_requests
metricName: http_requests
# target 500 milli-requests per second,
# which is 1 request every two seconds
targetAverageValue: 20m

View file

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: sample-app
name: sample-app
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app: sample-app
type: ClusterIP

View file

@ -0,0 +1,12 @@
kind: ServiceMonitor
apiVersion: monitoring.coreos.com/v1
metadata:
name: sample-app
labels:
app: sample-app
spec:
selector:
matchLabels:
app: sample-app
endpoints:
- port: http