Exercise in adding health probes to an application in Openshift.
- Deploy an application with HTTP endpoints to openshift
- Add readiness and liveness probes to the application
- Log in to the CLI of Openshift as the
developer
user. - Create a new project, e.g.
nodejs-helloworld
- Deploy the nodejs app we used in web-console intro lab:
$ oc new-app --name helloworld --env="WORLD_STATE=infected" svejkciber/nodejs-helloworld:00ce99e2badb634a700862bc97963a8d28032f46 ... --> Success Application is not exposed. You can expose services to the outside world by executing one or more of thecommands below: 'oc expose svc/helloworld' Run 'oc status' to view your app.
- Verify that the app is running with
oc status
,oc get pod
and view the running pod's log. - Expose an external HTTP route to the app (hint: just follow the advice given above)
- Test the app with a web broser or
curl
(hint: get the DNS name of the route fromoc get route
).
Since the application's default HTTP endpoint normally returns 200 OK
, we can simply reuse it for health probes.
Note that this is somewhat quick and dirty, in realistic applications one would usually implement dedicated endpoints for each probe, e.g. /isReady
and /isAlive
.
- Review Openshift's informational warning about missing health probes:
We will fix these issues soon.
$ oc status --suggest ... Info: * pod/helloworld-1-deploy has no liveness probe to verify pods are still running. try: oc set probe pod/helloworld-1-deploy --liveness ... * dc/helloworld has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful. try: oc set probe dc/helloworld --readiness ... * dc/helloworld has no liveness probe to verify pods are still running. try: oc set probe dc/helloworld --liveness ...
- Add a readiness probe to the deployment configuration:
$ oc set probe dc/helloworld --readiness --get-url=http://:8080/
- Verify that the probe is added to the
DeploymentConfiguration
We have added a readines probe with default parameter.$ oc describe dc/helloworld ... Pod Template: Labels: app=helloworld ... Containers: helloworld: ... Readiness: http-get http://:8080/ delay=0s timeout=1s period=10s #success=1 #failure=3 ...
This step is identical to the above probe configuration, except that the prope type argument in step 2
is --liveness
instead of --readiness
.
Run oc status
again to check that there are no more complaints of missing probes.
- Fork the Git repo of the nodejs-helloworld app at https://github.com/svejk-ciber/nodejs-helloworld.
- Perform a source build from your forked repo in Openshift. The
new-app
command becomes something like:You may have to specify the docker source strategy, if Openshift doesn't pick up that this is a Dockerfile build.$ oc new-app --name <NAME> --env="WORLD_STATE=<SOME STATE>" https://github.com/svejk-ciber/nodejs-helloworld
- Implement a couple of custom probe endpoints, e.g.
/isAlive
andisReady
. Tweak the implementations so that the probes fail. Observe Openhsift/Kubernetes behaviour on failing probes and adjust the probe implementations.