Skip to content

Instantly share code, notes, and snippets.

@mikamboo
Last active April 13, 2020 12:38
Show Gist options
  • Select an option

  • Save mikamboo/ca258701cbba4f374244f0ae62f1997b to your computer and use it in GitHub Desktop.

Select an option

Save mikamboo/ca258701cbba4f374244f0ae62f1997b to your computer and use it in GitHub Desktop.
Kubernetes : Ingress for url validation route

Ingress temporary route

Use case : Quickly create a location /loaderio-xxxxxxxx with text response loaderio-xxxxxxxx.

Eg : curl http://clouder.my-domain.io/clouder.my-domain.io must return :

loaderio-xxxxxxxx

Tip

  • Create a simple nginx:alpine deployment and live edit default config using kubectle exec -it pod-name-xxx.
  • Reload the config by sending au relaod signal : nginx -s reload

Tip

  • To avaoid exec in running pod : mount a configMap as a volume at /usr/share/nginx/html on nginx container.
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-loaderio
labels:
app: nginx-loaderio
data:
index.html: $LOADERIO_TOKEN
default.conf: |
server {
listen 80;
location = /loaderio-$LOADERIO_TOKEN {
return 200 '$LOADERIO_TOKEN';
add_header Content-Type text/plain;
}
}
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: nginx
labels:
k8s-app: nginx
spec:
replicas: 1
selector:
matchLabels:
k8s-app: nginx
template:
metadata:
name: nginx
creationTimestamp: null
labels:
k8s-app: nginx
spec:
volumes:
- name: nginx-conf-volume
configMap:
name: nginx-loaderio
containers:
- name: nginx
image: 'nginx:alpine'
- containerPort: 80
volumeMounts:
- name: nginx-conf-volume
mountPath: /etc/nginx/conf.d
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
labels:
k8s-app: nginx
name: nginx
spec:
rules:
- host: my-domain.org
http:
paths:
- backend:
serviceName: nginx
servicePort: tcp-80
path: /loaderio-${LOADERIO_TOKEN}$
---
kind: Service
apiVersion: v1
metadata:
name: nginx
labels:
k8s-app: nginx
spec:
ports:
- name: tcp-80
port: 80
targetPort: 80
selector:
k8s-app: nginx
@mikamboo
Copy link
Copy Markdown
Author

mikamboo commented Apr 12, 2020

Execute :

  1. Substitute env var token
  2. Kbectl apply configuration
LOADERIO_TOKEN=xxxxxx envsubst < nginx-loader-io.yaml | k apply -n loader -f -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment