How can I configure my Deployment to do a health check on the sprint boot actuator endpoint? I'm using spring boot 2 running on port 9000. (PS: port-forward test works)
This is the error:
Readiness probe failed: Get http://10.48.0.116:9000/actuator/health: dial tcp 10.48.0.116:9000: connect: connection refused
And that is my Deployment yml:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: my-api
namespace: vidolin
labels:
stack: api
app: my-api
spec:
replicas: 1
selector:
matchLabels:
stack: api
app: my-api
template:
metadata:
labels:
stack: api
app: my-api
spec:
imagePullSecrets:
- name: itdevregistry
containers:
- name: primary
image: vidolinregistry.azurecr.io/my/api
ports:
- containerPort: 9000
envFrom:
- configMapRef:
name: my-api-config
readinessProbe:
httpGet:
path: /actuator/health
port: 9000
initialDelaySeconds: 10
timeoutSeconds: 2
periodSeconds: 3
failureThreshold: 1
livenessProbe:
httpGet:
path: /actuator/health
port: 9000
initialDelaySeconds: 20
timeoutSeconds: 2
periodSeconds: 8
failureThreshold: 1
Although I am replying a bit late. But I think my implementation will help people in future to implement kubernetes readiness / liveness probe for spring boot applications.
Description of my docker image
So I cannot use httpGet option of kubernetes, as it uses http protocol only.
That is why I create a small shell script "check-if-healthy.sh" as part of docker image to know the status
check-if-healthy.sh
===================
curl -k https://localhost:8888/actuator/health | grep '"status":"UP"' > /dev/null && exit 0 || exit 1
Please note you need to add this script into docker image, so that it will be available in running container and accessible to kubernetes, As kubernetes will fire "docker exec /bin/ash /home/config-server/check-if-healthy." like this
COPY docker/check-if-healthy.sh /home/config-server/check-if-healthy.sh
And then used "exec" option of kubernetes readiness probe to call the script like this.
readinessProbe:
exec:
command:
- /bin/ash
- /home/config-server/check-if-healthy.sh
initialDelaySeconds: 5
timeoutSeconds: 1
failureThreshold: 50
livenessProbe:
exec:
command:
- /bin/ash
- /home/config-server/check-if-healthy.sh
initialDelaySeconds: 5
timeoutSeconds: 1
failureThreshold: 50