Last active
March 21, 2019 10:19
-
-
Save brouberol/546c050b542e4f247e25e68f7f4c0599 to your computer and use it in GitHub Desktop.
k8s pod readiness http API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: test-readiness-balthazar-readiness-pod-script | |
namespace: datadog | |
data: | |
readiness-pod.py: | | |
#!/usr/bin/env python3 | |
import os | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
class ReadinessCheck(BaseHTTPRequestHandler): | |
def is_ready(self): | |
ready = os.path.exists('/ready') | |
if ready: | |
print("Ready!") | |
else: | |
print("Not ready..") | |
return ready | |
def do_GET(self): | |
if self.is_ready(): | |
self.send_response(200) | |
else: | |
self.send_response(400) | |
self.end_headers() | |
self.wfile.write(b'') | |
def main(): | |
HTTPServer(('', 8080), ReadinessCheck).serve_forever() | |
if __name__ == '__main__': | |
main() | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: test-readiness-balthazar | |
namespace: datadog | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: test-readiness-balthazar | |
template: | |
metadata: | |
labels: | |
app: test-readiness-balthazar | |
spec: | |
serviceAccountName: cassandra | |
affinity: | |
nodeAffinity: | |
requiredDuringSchedulingIgnoredDuringExecution: | |
nodeSelectorTerms: | |
- matchExpressions: | |
- key: node-role.kubernetes.io/cassandra-contexts | |
operator: Exists | |
tolerations: | |
- key: node | |
operator: Exists | |
effect: NoSchedule | |
volumes: | |
- name: readiness-pod-script | |
configMap: | |
name: test-readiness-balthazar-readiness-pod-script | |
defaultMode: 0755 | |
containers: | |
- name: main-pod | |
image: cassandra-toolbox:3.11 | |
imagePullPolicy: IfNotPresent | |
resources: | |
limits: | |
cpu: 100m | |
memory: 128Mi | |
requests: | |
cpu: 100m | |
memory: 128Mi | |
command: | |
- /bin/bash | |
- -c | |
- "sleep infinity" | |
- name: readiness-pod | |
image: cassandra-toolbox:3.11 | |
imagePullPolicy: IfNotPresent | |
volumeMounts: | |
- name: readiness-pod-script | |
mountPath: /tmp | |
resources: | |
limits: | |
cpu: 100m | |
memory: 64Mi | |
requests: | |
cpu: 100m | |
memory: 64Mi | |
readinessProbe: | |
httpGet: | |
path: / | |
port: 8080 | |
initialDelaySeconds: 3 | |
periodSeconds: 3 | |
command: | |
- /tmp/readiness-pod.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment