We will create two namespaces, mesh, which is where the service mesh resides, and the blue namespace where our apps reside.
We will create a service in the mesh namespace called mesh, and a corresponding service of type ExternalName in the blue namespace called mesh-external, representing the mesh service in the mesh namespace.
kubectl create ns mesh
kubectl create ns blue
kubectl run mesh --image=nginx:alpine --port=80 -n mesh
kubectl expose pod/mesh -n mesh --type=LoadBalancer # important because the Service itself needs an IP
kubectl apply -f -<<EOF
kind: Service
apiVersion: v1
metadata:
name: mesh-external
namespace: blue
spec:
type: ExternalName
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
externalName: mesh.mesh.svc.cluster.local
EOF
Create the curler pod
kubectl run curler --image=nginx:alpine -n blue
Curl against the externalName service
kubectl exec -it curler -n blue -- curl mesh-external
output
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Wait & Create Route
# Wait for IP to be present
until [ -n "$(kubectl get svc/mesh -n mesh -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" ]; do
sleep 7
done
kubectl apply -f -<<EOF
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: mesh-external
namespace: blue
spec:
host: $(kubectl get svc mesh -n mesh -ojsonpath='{.status.loadBalancer.ingress[0].ip}')
port:
targetPort: http
to:
kind: Service
name: mesh-external
EOF
Curl against OpenShift Route
curl $(kubectl get route mesh-external -n blue -ojsonpath='{.spec.host}')
output
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Clean Up
kubectl delete po,svc mesh --force -n mesh --grace-period=0
kubectl delete svc mesh-external -n blue --force --grace-period=0
kubectl delete pod/curler -n blue --force --grace-period=0
kubectl delete route --all -n blue
kubectl delete ns blue
kubectl delete ns mesh