Add an HTTP echo service to your Kubernetes cluster
Kubernetes is a lot of fun and also a maze of settings and services. When working on your Ingress rules, it's good to have something on the inside to validate your configuration. Echo service to the rescue!
Example
Imagine you've got a bunch of services in your cluster, sharing a common base path (in this case /api/echo
). And you've got ingress in place to manage routing. To see "what gets through" is especially useful when you're using Ingress' URL rewriting. Just to make sure that your regexes are correct. How do you check that?
$ curl "https://<your-host>/api/echo/some/demo?thingy=Y"
By running this command line curl
request, you can see that the rewrite rule transforms it to the path in line 3 (stripping /api/echo
from the path).
Request served by echo-deployment-8475b5cddd-bzg7v
HTTP/1.1 GET /some/demo?thingy=Y
Host: <your-host>
Accept: */*
X-Real-Ip: 10.240.0.4
X-Forwarded-For: 10.240.0.4
X-Forwarded-Host: <your-host>
X-Forwarded-Port: 443
X-Forwarded-Proto: https
X-Original-Uri: /api/echo/some/demo?thingy=Y
X-Request-Id: 3822dd5ca8545c3222544392d692f212
X-Scheme: https
User-Agent: curl/7.54.0
The service just returns a response containing as much as it could gather from your request.
Deployment
I used this echo-server and configured a simple deployment for it:
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-deployment
spec:
replicas: 1
selector:
matchLabels:
app: echo-server
template:
metadata:
labels:
app: echo-server
spec:
containers:
- name: echo-server
image: jmalloc/echo-server
ports:
- name: http-port
containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: echo-service
spec:
ports:
- name: http-port
port: 80
targetPort: http-port
protocol: TCP
selector:
app: echo-server
Some ingress rules to test
Next, we need some rules including rewrites to test stuff. I won't go into the details of that, there's enough examples out there. Just add one rewrite rule for your echo service, matching the other rules, and you've got a working setup.
- path: /api/echo/?(.*)
backend:
serviceName: echo-service
servicePort: 80
Now, when you run the curl command from the start of this post, it should answer correctly!