Creating a service network with OpenShift
This tutorial demonstrates how to connect a frontend service on a OpenShift cluster with a backend service on a OpenShift cluster using the skupper command-line interface (CLI).
See Overview for an introduction to Skupper.
-
Access to projects in two OpenShift clusters,
cluster-adminaccess is not required. -
One of the OpenShift clusters must be addressable from the other cluster.
-
kubectlandocCLI. Many commands can be performed usingoc, however this tutorial shows thekubectloptions.
This tutorial shows how to connect the following namespaces:
-
west- runs the frontend service and is typically a public cluster. -
east- runs the backend service.
1. Installing the skupper CLI
Installing the skupper command-line interface (CLI) provides a simple method to get started with Skupper.
-
Install the
skuppercommand-line interface.For Linux:
$ curl -fL https://github.com/skupperproject/skupper/releases/download/1.0/skupper-cli-1.0-linux-amd64.tgz | tar -xzf -
For MacOS:
$ curl -fL https://github.com/skupperproject/skupper/releases/download/1.0/skupper-cli-1.0-mac-amd64.tgz | tar -xzf -
-
Copy the
skupperexecutable to a directory in your $PATH:$ mkdir -p $HOME/bin $ export PATH=$PATH:$HOME/bin $ mv skupper $HOME/bin
-
Verify the installation.
$ skupper version client version 1.0
2. Configuring terminal sessions
This procedure describes how to configure your terminal sessions to use configurations to avoid problems as you configure Skupper on different clusters.
The following table shows how you might set up your terminal sessions.
| west terminal session | east terminal session |
|---|---|
|
|
-
The OpenShift CLI is installed. See the OpenShift CLI documentation for more instructions on how to install
oc.
| In OpenShift 4.6 and later, you can use the web terminal to perform the following procedure, as described in the web terminal documentation. |
-
Start a terminal session to work on the
westnamespace and set theKUBECONFIGenvironment variable:$ export KUBECONFIG=$HOME/.kube/config-westThis session is referred to later as the west terminal session.
-
Start a terminal session to work on the
eastnamespace and set theKUBECONFIGenvironment variable:$ export KUBECONFIG=$HOME/.kube/config-eastThis session is referred to later as the east terminal session.
-
In each terminal session, log into the OpenShift cluster.
3. Installing the service network router in both clusters
-
In the west terminal session:
-
Create the
westproject (namespace):$ kubectl create namespace west $ kubectl config set-context --current --namespace west -
Create the service network router:
$ skupper init -
Check the site status:
$ skupper statusThe output should be similar to the following:
Skupper enabled for namespace 'west'. It is not connected to any other sites.
-
-
In the east terminal session:
-
Create the
eastproject (namespace):$ kubectl create namespace east $ kubectl config set-context --current --namespace east -
Create the service network router:
$ skupper init -
Check the site status:
$ skupper statusThe output should be similar to the following:
Skupper enabled for namespace 'east'. It is not connected to any other sites.
-
4. Connecting namespaces to create a service network
With the service network routers installed, you can connect them together securely and allow service sharing across the service network.
-
In the west terminal session, create a connection token to allow connection to the west namespace:
$ skupper token create $HOME/secret.yamlThis command creates the
secret.yamlfile in your home directory, which you can use to create the secure connection. -
In the east terminal session, use the token to create a connection to the west namespace:
$ skupper link create $HOME/secret.yaml -
Check the site status from the west terminal session:
$ skupper statusThe output should be similar to the following:
Skupper is enabled for namespace "west" in interior mode. It is connected to 1 other site. It has no exposed services. The site console url is: https://<skupper-url> The credentials for internal console-auth mode are held in secret: 'skupper-console-users'
5. Creating the frontend service
The frontend service is a simple Python application that displays a message from the backend application.
Perform all tasks in the west terminal session:
-
Deploy the frontend service:
$ kubectl create deployment hello-world-frontend --image quay.io/skupper/hello-world-frontend -
Expose the frontend deployment as a cluster service:
$ kubectl expose deployment hello-world-frontend --port 8080 --type LoadBalancer -
Create a route for the frontend:
$ kubectl expose svc/hello-world-frontend -
Check the frontend route:
-
Get the route details:
$ oc get routesThe output should be similar to the following:
NAME HOST/PORT hello-world-frontend <frontend-url>
-
Navigate to the
<frontend-url>value in your browser, you see a message similar to the following because the frontend cannot communicate with the backend yet:Trouble! HTTPConnectionPool(host='hello-world-backend', port=8080): Max retries exceeded with url: /api/hello (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbfcdf0d1d0>: Failed to establish a new connection: [Errno -2] Name or service not known'))To resolve this situation, you must create the backend service and make it available on the service network.
-
6. Creating the backend service and making it available on the service network
The backend service runs in the east namespace and is not available on the service network by default.
You use the skupper command to expose the service to all namespaces on the service network.
The backend app is a simple Python application that passes a message to the frontend application.
-
Deploy the backend service in the east terminal session:
$ kubectl create deployment hello-world-backend --image quay.io/skupper/hello-world-backend -
Expose the backend service on the service network from the east terminal session:
$ skupper expose deployment hello-world-backend --port 8080 --protocol tcp -
Check the site status from the west terminal session:
$ skupper statusThe output should be similar to the following:
Skupper is enabled for namespace "west" in interior mode. It is connected to 1 other site. It has 1 exposed service.
The service is exposed from the
eastnamespace. -
Check the frontend route in the west terminal session:
-
Get the route details:
$ oc get routesThe output should be similar to the following:
NAME HOST/PORT hello-world-frontend <frontend-url>
-
Navigate to the
<frontend-url>value in your browser, you see a message similar to the following:Hi, <name>. I am Mathematical Machine (backend-77f8f45fc8-mnrdp).
If you click Say hello again, a different backend process responds showing how Skupper balances the requests.
-
This shows how the frontend calls the backend service over the service network from a different OpenShift cluster.