Skip to content

Instantly share code, notes, and snippets.

@codersofthedark
Created November 5, 2019 10:31
Show Gist options
  • Save codersofthedark/63abc9709f6e375b71bdf33bed3cde84 to your computer and use it in GitHub Desktop.
Save codersofthedark/63abc9709f6e375b71bdf33bed3cde84 to your computer and use it in GitHub Desktop.
For running an echo server for regular and web socket on kubernetes

Echo Server

A very simple HTTP echo server with support for web-sockets.

Any messages sent from a web-socket client are echoed.
Visit /.ws for a basic UI to connect and send web-socket messages.
Requests to any other URL will return the request headers and body.
The PORT environment variable sets the server port.
Set the LOG_HTTP_BODY environment variable to dump request bodies to STDOUT.
No TLS support yet :(

Ref: https://github.com/jmalloc/echo-server/blob/master/README.md

# Deployment to run 1 pod container of echo-server
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-server
labels:
app: echo-server
spec:
replicas: 1
selector:
matchLabels:
app: echo-server
template:
metadata:
labels:
app: echo-server
spec:
containers:
- name: echo-server
image: jmalloc/echo-server
ports:
- containerPort: 8080
# Creating Kubernetes Service to expose 8080 to 80
---
apiVersion: v1
kind: Service
metadata:
name: echo-server
spec:
selector:
app: echo-server
ports:
- protocol: TCP
port: 80
targetPort: 8080
# Creating Ingress to map service at port 80 to an external sub domain
# Change something.com to the domain you own
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echo-server
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: echo-server.something.com
http:
paths:
- path: /
backend:
serviceName: echo-server
servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment