Skip to content

Commit dfc399f

Browse files
committed
Add liveness and readiness probe
1 parent 36f7972 commit dfc399f

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

openshift/templates/django-postgresql.json

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@
164164
"containerPort": 8080
165165
}
166166
],
167+
"readinessProbe": {
168+
"timeoutSeconds": 3,
169+
"initialDelaySeconds": 3,
170+
"httpGet": {
171+
"path": "/health",
172+
"port": 8080
173+
}
174+
},
175+
"livenessProbe": {
176+
"timeoutSeconds": 3,
177+
"initialDelaySeconds": 30,
178+
"httpGet": {
179+
"path": "/health",
180+
"port": 8080
181+
}
182+
},
167183
"env": [
168184
{
169185
"name": "DATABASE_SERVICE_NAME",
@@ -195,9 +211,9 @@
195211
}
196212
],
197213
"resources": {
198-
"limits": {
199-
"memory": "${MEMORY_LIMIT}"
200-
}
214+
"limits": {
215+
"memory": "${MEMORY_LIMIT}"
216+
}
201217
}
202218
}
203219
]
@@ -294,10 +310,24 @@
294310
"value": "${DATABASE_NAME}"
295311
}
296312
],
313+
"readinessProbe": {
314+
"timeoutSeconds": 1,
315+
"initialDelaySeconds": 5,
316+
"exec": {
317+
"command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U ${POSTGRESQL_USER} -q -d ${POSTGRESQL_DATABASE} -c 'SELECT 1'"]
318+
}
319+
},
320+
"livenessProbe": {
321+
"timeoutSeconds": 1,
322+
"initialDelaySeconds": 30,
323+
"tcpSocket": {
324+
"port": 5432
325+
}
326+
},
297327
"resources": {
298-
"limits": {
299-
"memory": "${MEMORY_POSTGRESQL_LIMIT}"
300-
}
328+
"limits": {
329+
"memory": "${MEMORY_POSTGRESQL_LIMIT}"
330+
}
301331
}
302332
}
303333
]

openshift/templates/django.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@
164164
"containerPort": 8080
165165
}
166166
],
167+
"readinessProbe": {
168+
"timeoutSeconds": 3,
169+
"initialDelaySeconds": 3,
170+
"httpGet": {
171+
"path": "/",
172+
"port": 8080
173+
}
174+
},
175+
"livenessProbe": {
176+
"timeoutSeconds": 3,
177+
"initialDelaySeconds": 30,
178+
"httpGet": {
179+
"path": "/",
180+
"port": 8080
181+
}
182+
},
167183
"env": [
168184
{
169185
"name": "DATABASE_SERVICE_NAME",

project/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
# url(r'^blog/', include('blog.urls')),
88

99
url(r'^$', 'welcome.views.index'),
10+
url(r'^health$', 'welcome.views.health'),
1011
url(r'^admin/', include(admin.site.urls)),
1112
]

welcome/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from django.shortcuts import render
33
from django.conf import settings
4+
from django.http import HttpResponse
45

56
from . import database
67
from .models import PageView
@@ -16,3 +17,6 @@ def index(request):
1617
'database': database.info(),
1718
'count': PageView.objects.count()
1819
})
20+
21+
def health(request):
22+
return HttpResponse(PageView.objects.count())

0 commit comments

Comments
 (0)