4. Configure Applications for Reliability Flashcards
- Configure and use health probes
Health probes are an important part of maintaining a robust cluster. Probes enable the cluster to determine the status of an application by repeatedly probing it for a response.
A set of health probes affect a cluster’s ability to do the following tasks:
Crash mitigation by automatically attempting to restart failing pods
Failover and load balancing by sending requests only to healthy pods
Monitoring by determining whether and when pods are failing
Scaling by determining when a new replica is ready to receive requests
Probe Types
A readiness probe determines whether the application is ready to serve requests.
If the readiness probe fails, then Kubernetes prevents client traffic from reaching the application by removing the pod’s IP address from the service resource.
A liveness probe is called throughout the lifetime of the application.
Liveness probes determine whether the application container is in a healthy state.
Types of Tests: HTTP GET, Conatiner Command, TCP socket
Probes
# add probes in existing deployment
## -c/–containers flag can be added in command below to specify a container
## HTTP GET
oc set probe deploy/long-load –readiness –get-url http://:3000/health –failure-threshold 1 –period-seconds 3
## Container Command
oc set probe deploy/long-load –liveness – ping -c3 localhost
### TCP socket
oc set probe deploy/db –readiness –open-tcp=3306
# remove liveness & readiness
oc set probe deploy/myapp –remove –readiness –liveness
- Reserve and limit application compute capacity
Set resources requests/limits
Verify nodes, pods resources usage
Resources - Requests/Limits
## add resources requests/limits
oc set resources deployment hello-world-nginx –requests cpu=10m,memory=1gi –limits cpu=300m,memory=2gi
## verify resources usage
oc adm top pods -A –sum
oc adm top node mynode
## view totoal memory/cpu requets for a node
oc describe node master01
- Scale applications to meet increased demand
Configure a horizontal pod autoscaler: HPA
HPA
oc autoscale deployment/hello –name hello-hpa –min 1 –max 10 –cpu-percent 80
oc get hpa
# configure hpa based on memory
## oc autoscale don’t provide option to create hpa based on memory usage
## you should create a manifest
oc explain hpa.spec
oc explain hpa.spec.metrics.resource
##e.g scales up when the average memory usage is above 60% of the memory requests value, and scales down when the usage is below this percentage.
## min 1 and max 3
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
labels:
app: myapp
spec:
maxReplicas: 3
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 60