diff --git a/kubernetes/autoscaling/components/metric-server/metricserver-0.3.7.yaml b/kubernetes/autoscaling/components/metric-server/metricserver-0.3.7.yaml index 0bb04da..52c12fa 100644 --- a/kubernetes/autoscaling/components/metric-server/metricserver-0.3.7.yaml +++ b/kubernetes/autoscaling/components/metric-server/metricserver-0.3.7.yaml @@ -88,8 +88,8 @@ spec: args: - --cert-dir=/tmp - --secure-port=4443 - #- --kubelet-insecure-tls - #- --kubelet-preferred-address-types="InternalIP" + - --kubelet-insecure-tls + - --kubelet-preferred-address-types="InternalIP" ports: - name: main-port containerPort: 4443 diff --git a/kubernetes/autoscaling/readme.md b/kubernetes/autoscaling/readme.md index 0d840b3..b2d357b 100644 --- a/kubernetes/autoscaling/readme.md +++ b/kubernetes/autoscaling/readme.md @@ -170,3 +170,12 @@ kubectl get hpa/application-cpu -owide kubectl describe hpa/application-cpu ``` + +## Vertical Pod Autoscaling + +The vertical pod autoscaler allows us to automatically set request values on our pods
+based on recommendations. +This helps us tune the request values based on actual CPU and Memory usage.
+ +More [here](./vertical-pod-autoscaling/readme.md) + diff --git a/kubernetes/autoscaling/vertical-pod-autoscaling/readme.md b/kubernetes/autoscaling/vertical-pod-autoscaling/readme.md new file mode 100644 index 0000000..9b26194 --- /dev/null +++ b/kubernetes/autoscaling/vertical-pod-autoscaling/readme.md @@ -0,0 +1,141 @@ +# Vertical Pod Autoscaling + +## We need a Kubernetes cluster + +Lets create a Kubernetes cluster to play with using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) + +``` +kind create cluster --name vpa --image kindest/node:v1.19.1 +``` +
+ +## Metric Server + +
+ +* For `Cluster Autoscaler` - On cloud-based clusters, Metric server may already be installed.
+* For `HPA` - We're using kind + +[Metric Server](https://github.com/kubernetes-sigs/metrics-server) provides container resource metrics for use in autoscaling pipelines
+ +Because I run K8s `1.19` in `kind`, the Metric Server version i need is `0.3.7`
+We will need to deploy Metric Server [0.3.7](https://github.com/kubernetes-sigs/metrics-server/releases/tag/v0.3.7)
+I used `components.yaml`from the release page link above.
+ +Important Note : For Demo clusters (like `kind`), you will need to disable TLS
+You can disable TLS by adding the following to the metrics-server container args
+ +For production, make sure you remove the following :
+ +``` +- --kubelet-insecure-tls +- --kubelet-preferred-address-types="InternalIP" + +``` + +Deployment:
+ +``` +cd kubernetes\autoscaling +kubectl -n kube-system apply -f .\components\metric-server\metricserver-0.3.7.yaml + +#test +kubectl -n kube-system get pods + +#note: wait for metrics to populate! +kubectl top nodes + +``` + +## VPA + +VPA docs [here]("https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler#install-command")
+Let's install the VPA from a container that can access our cluster + +``` +cd kubernetes/autoscaling/vertical-pod-autoscaling +docker run -it --rm -v ${HOME}:/root/ -v ${PWD}:/work -w /work --net host debian:buster bash + +# install git +apt-get update && apt-get install -y git curl + +# install kubectl +curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl +chmod +x ./kubectl +mv ./kubectl /usr/local/bin/kubectl + + +cd /tmp +git clone https://github.com/kubernetes/autoscaler.git +cd autoscaler/vertical-pod-autoscaler/ + +./hack/vpa-up.sh + +# after few seconds, we can see the VPA components in: + +kubectl -n kube-system get pods +``` + +## Build and deploy example app + +``` +# build + +cd kubernetes\autoscaling\components\application +docker build . -t aimvector/application-cpu:v1.0.0 + +# push +docker push aimvector/application-cpu:v1.0.0 + +# deploy +kubectl apply -f deployment.yaml + +# metrics +kubectl top pods + +``` + +## Generate some traffic + +Let's deploy a simple traffic generator pod + +``` +cd kubernetes\autoscaling\components\application +kubectl apply -f .\traffic-generator.yaml + +# get a terminal to the traffic-generator +kubectl exec -it traffic-generator sh + +# install wrk +apk add --no-cache wrk + +# simulate some load +wrk -c 5 -t 5 -d 99999 -H "Connection: Close" http://application-cpu + +``` + +# Deploy an example VPA + +``` + +kubectl apply -f .\vertical-pod-autoscaling\vpa.yaml + +kubectl describe vpa application-cpu + +``` + +# Deploy Goldilocks + +``` +cd /tmp +git clone https://github.com/FairwindsOps/goldilocks.git +cd goldilocks/hack/manifests/ + +kubectl create namespace goldilocks +kubectl -n goldilocks apply -f ./controller +kubectl -n goldilocks apply -f ./dashboard + + +kubectl label ns default goldilocks.fairwinds.com/enabled=true +kubectl label ns default goldilocks.fairwinds.com/vpa-update-mode="off" +``` \ No newline at end of file diff --git a/kubernetes/autoscaling/vertical-pod-autoscaling/vpa.yaml b/kubernetes/autoscaling/vertical-pod-autoscaling/vpa.yaml new file mode 100644 index 0000000..118da5f --- /dev/null +++ b/kubernetes/autoscaling/vertical-pod-autoscaling/vpa.yaml @@ -0,0 +1,11 @@ +apiVersion: autoscaling.k8s.io/v1 +kind: VerticalPodAutoscaler +metadata: + name: application-cpu +spec: + targetRef: + apiVersion: "apps/v1" + kind: Deployment + name: application-cpu + updatePolicy: + updateMode: "Off" \ No newline at end of file