Skip to content

Instantly share code, notes, and snippets.

@kincl
Created August 28, 2023 20:36
Show Gist options
  • Save kincl/4aef1d9150c91e59b455c9aa0bfe8851 to your computer and use it in GitHub Desktop.
Save kincl/4aef1d9150c91e59b455c9aa0bfe8851 to your computer and use it in GitHub Desktop.
python-based echo headers for kubernetes
apiVersion: v1
kind: ConfigMap
metadata:
name: python-http
labels:
app: python-http
data:
app.py: |
from http.server import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
# print("Request headers:", self.headers)
self.send_response(200)
self.send_header("Content-type", "text")
self.end_headers()
for k,v in self.headers.items():
self.wfile.write(bytes(f"{k}: {v}\n", "utf-8"))
def main():
print('Listening on 0.0.0.0:8080')
server = HTTPServer(('', 8080), RequestHandler)
server.serve_forever()
if __name__ == "__main__":
main()
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-http
labels:
app: python-http
spec:
replicas: 1
selector:
matchLabels:
app: python-http
template:
metadata:
labels:
app: python-http
spec:
terminationGracePeriodSeconds: 1
containers:
- image: image-registry.openshift-image-registry.svc:5000/openshift/python:latest
command:
- python3
- /application/app.py
name: python
volumeMounts:
- name: app
mountPath: /application
volumes:
- name: app
configMap:
name: python-http
---
apiVersion: v1
kind: Service
metadata:
labels:
app: python-http
name: python-http
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: python-http
type: ClusterIP
---
kind: Route
apiVersion: route.openshift.io/v1
metadata:
labels:
app: python-http
name: python-http
spec:
to:
kind: Service
name: python-http
weight: 100
port:
targetPort: http
tls:
termination: edge
insecureEdgeTerminationPolicy: Redirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment