Last active
August 2, 2024 19:09
-
-
Save kincl/4aef1d9150c91e59b455c9aa0bfe8851 to your computer and use it in GitHub Desktop.
python-based echo headers for kubernetes
This file contains hidden or 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: python-http | |
labels: | |
app: python-http | |
data: | |
app.py: | | |
import logging | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
class RequestHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
# print("Request headers:", self.headers) | |
logging.info("GET request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(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(): | |
logging.basicConfig(level=logging.INFO) | |
logging.info('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