HPA (Horizontal Pod Autoscaling)
- For this to work we need metrics server to be running.
- Refer Here for hpa official docs
- Lets create a nginx deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
resources:
limits:
cpu: 250m
memory: 256Mi
- name: alpine
image: alpine
args:
- sleep
- 1d
- Lets create a hpa
kubectl autoscale deployment nginx-deployment --cpu-percent=50 --min=1 --max=10
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-deployment
spec:
maxReplicas: 10
metrics:
- resource:
name: cpu
target:
averageUtilization: 50
type: Utilization
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
- Lets create a service called as nginx with cluster ip
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
app: nginx
ports:
- name: websvc
protocol: TCP
port: 80
targetPort: 80
- Lets make the application busy
kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://nginx-svc; done"
Cluster Autoscaler
- Every Managed k8s has a cluster autoscaler
- There are some of the toolings around autoscaling
Kubernetes Lens (UI Based Client)
Helm – Package Manager for k8s
- Chart: An Application/Component to be deployed
- Repository: This hosts Charts
- Try installing
- wordpress
- prometheus and grafana
- redis cache
- To Author:
- Go Template
- use helm playground
Like this:
Like Loading...