Skip to content

Instantly share code, notes, and snippets.

@ironcladlou
Created July 29, 2019 21:42
Show Gist options
  • Save ironcladlou/6f11d01debacb41b7a7093117abc7fc4 to your computer and use it in GitHub Desktop.
Save ironcladlou/6f11d01debacb41b7a7093117abc7fc4 to your computer and use it in GitHub Desktop.
Private ingresscontroller demo
kind: Namespace
apiVersion: v1
metadata:
name: private-hello
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: hello
namespace: private-hello
spec:
replicas: 1
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: openshift/hello-openshift
---
kind: Service
apiVersion: v1
metadata:
name: hello
namespace: private-hello
spec:
selector:
app: hello
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: v1
kind: Route
metadata:
name: public
namespace: private-hello
spec:
host: hello.public.dmace.devcluster.openshift.com
to:
kind: Service
name: hello
---
apiVersion: v1
kind: Route
metadata:
name: private
namespace: private-hello
labels:
scope: internal
spec:
host: hello.private.dmace.devcluster.openshift.com
to:
kind: Service
name: hello
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
namespace: openshift-ingress-operator
name: public
spec:
domain: public.dmace.devcluster.openshift.com
endpointPublishingStrategy:
type: LoadBalancerService
routeSelector:
matchExpressions:
- {key: scope, operator: NotIn, values: [internal]}
---
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
namespace: openshift-ingress-operator
name: private
spec:
domain: private.dmace.devcluster.openshift.com
endpointPublishingStrategy:
type: LoadBalancerService
loadBalancer:
scope: Internal
routeSelector:
matchLabels:
scope: internal
#!/bin/bash
set -euo pipefail
oc apply -f ingresscontrollers.yaml
oc apply -f app.yaml
From a host outside the cluster on the internet:
$ dig +short hello.public.dmace.devcluster.openshift.com
3.13.23.237
3.130.125.169
$ dig +short hello.private.dmace.devcluster.openshift.com
$ curl -s http://hello.public.dmace.devcluster.openshift.com
Hello OpenShift!
$ curl -s http://hello.private.dmace.devcluster.openshift.com
<host not found>
From a pod in the cluster:
$ oc run --rm -i network-utils --image=amouat/network-utils --restart=Never --generator run-pod/v1 -- dig +short hello.public.dmace.devcluster.openshift.com
3.13.23.237
3.130.125.169
$ oc run --rm -i network-utils --image=amouat/network-utils --restart=Never --generator run-pod/v1 -- dig +short hello.private.dmace.devcluster.openshift.com
10.0.163.44
10.0.154.9
$ oc run --rm -i network-utils --image=amouat/network-utils --restart=Never --generator run-pod/v1 -- curl -s http://hello.public.dmace.devcluster.openshift.com
Hello OpenShift!
$ oc run --rm -i network-utils --image=amouat/network-utils --restart=Never --generator run-pod/v1 -- curl -s http://hello.private.dmace.devcluster.openshift.com
Hello OpenShift!
#!/bin/bash
set -x
dig +short hello.public.dmace.devcluster.openshift.com
dig +short hello.private.dmace.devcluster.openshift.com
curl -s http://hello.public.dmace.devcluster.openshift.com
curl -s http://hello.private.dmace.devcluster.openshift.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment