Using Skupper to connect multiple Kubernetes clusters

Skupper is a Layer 7 service interconnect that enables multicloud communication across Kubernetes clusters. There are a few reasons you might need to communicate between a local cluster and a remote one in development:

  • A service is deployed on the remote cluster, and you want to consume it with a local cluster.
  • A workload is high resource-consuming, and it is not feasible to deploy it on the local cluster given the available resources.
  • An existing stage/test database service is deployed on a remote cluster, and your workload needs to connect to it.

One of the best things about Skupper is that users don’t need to have admin privileges for the cluster to deploy it. See the article Skupper.io: Let your services communicate across Kubernetes clusters for more information about the open source project.

This article will show you how to use Skupper to connect a remote cluster service with a local cluster using Red Hat CodeReady Containers and the Developer Sandbox for Red Hat OpenShift. For a more detailed overview, refer to the Skupper getting started guide.

About the example

In this example, I am using Red Hat CodeReady Containers (CRC) for my local cluster. CodeReady Containers is a developer tool that lets you create local Kubernetes clusters on Red Hat OpenShift 4. I have another cluster from the Developer Sandbox for Red Hat OpenShift that I can access from anywhere.

Step 1: Install the Skupper command-line tool

First, install the Skupper command-line tool on your Linux system.

Note: If you are using a different platform, refer to the instructions in the getting started guide.

$ curl -fL https://github.com/skupperproject/skupper/releases/download/0.3.2/skupper-cli-0.3.2-linux-amd64.tgz | tar -xzf -

$ sudo mv skupper /usr/local/bin

$ which skupper 
/usr/local/bin/skupper

$ skupper --version
skupper version 0.3.2

Step 2: Configure access to multiple namespaces

As the getting started guide describes, the skupper command uses the kubeconfig file and the current context to select the namespace where it operates. You must use a distinct kubeconfig or context for each namespace, so it’s best to use different console terminals, tabs, or sessions.

Start a console session for each namespace and log in to your clusters.

CodeReady Containers console:

$ export KUBECONFIG=$HOME/.kube/config-crc

$ oc login -u developer -p developer https://api.crc.testing:6443
Login successful.

$ oc config get-contexts
CURRENT   NAME                              CLUSTER                AUTHINFO    NAMESPACE
*         /api-crc-testing:6443/developer   api-crc-testing:6443   developer

Developer Sandbox console:

$ export KUBECONFIG=$HOME/.kube/config-devsandbox

$ oc login --token=<token> --server=https://api.sandbox-m2.ll9k.p1.openshiftapps.com:6443
Logged into "https://api.sandbox-m2.ll9k.p1.openshiftapps.com:6443" as "prkumar" using the token provided.
You have access to the following projects and can switch between them with ' project <projectname>':
* prkumar-code
prkumar-dev
prkumar-stage

$ oc config get-contexts
CURRENT   NAME                                                                 CLUSTER                                         AUTHINFO   NAMESPACE
*         prkumar-code/api-sandbox-m2-ll9k-p1-openshiftapps-com:6443/prkumar   api-sandbox-m2-ll9k-p1-openshiftapps-com:6443   prkumar    prkumar-code

Next, create a new project on CodeReady Containers. For this demo's purposes, we’ll use prkumar-code as the default context for the Developer Sandbox side because we don’t have permission to create a new project.

CodeReady Containers console:

$ oc new-project demo
Now using project "demo" on server "https://api.crc.testing:6443".

Step 3: Install the Skupper router in each namespace

Run the skupper init command to install the router in each namespace.

CodeReady Containers console:

$ skupper init --cluster-local
Skupper is now installed in namespace 'demo'.  Use 'skupper status' to get more information.

Developer Sandbox console:

$ skupper init
Skupper is now installed in namespace 'prkumar-code'.  Use 'skupper status' to get more information.

Now, check if the route is successfully installed.

CodeReady Containers console:

$ skupper status
Skupper is enabled for namespace "prkumar-code" in interior mode. It is not connected to any other sites. It has no exposed services.

Step 4: Connect your namespaces

Generate the connection token.

Developer Sandbox console:

$ skupper connection-token $HOME/secret.yaml
Connection token written to /home/prkumar/secret.yaml

Then, use the token to connect to your CRC cluster.

CodeReady Containers console:

$ skupper connect $HOME/secret.yaml
Skupper configured to connect to skupper-inter-router-prkumar-code.apps.sandbox-m2.ll9k.p1.openshiftapps.com:443 (name=conn1)

Step 5: Expose your front-end and back-end services

Here we will use a back-end and a front-end service, as mentioned in the getting started guide. First, we will deploy the back-end service on the Developer Sandbox and the front-end service to CRC. Then, we’ll connect the back end with the front end.

CodeReady Containers console:

$ oc  create deployment hello-world-frontend --image quay.io/skupper/hello-world-frontend
deployment.apps/hello-world-frontend created

Developer Sandbox console:

$ oc create deployment hello-world-backend --image quay.io/skupper/hello-world-backend
deployment.apps/hello-world-backend created

Use the skipper expose command to expose the back-end service so it will be available on your CRC cluster.

Developer Sandbox console:

$ skupper expose deployment hello-world-backend --port 8080 --protocol http

As you can see, once you expose a service using Skupper, it is visible to the CRC cluster.

CodeReady Containers console:

$ oc get svc
NAME                  TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)               AGE

hello-world-backend   ClusterIP   10.217.5.209   <none>        8080/TCP              96s

Finally, test your front-end application to verify it can communicate with the back-end service.

CodeReady Containers console:

$ oc expose deployment hello-world-frontend --port 8080
service/hello-world-frontend exposed

$ oc expose svc hello-world-frontend
route.route.openshift.io/hello-world-frontend exposed

$ curl hello-world-frontend-demo.apps-crc.testing
I am the frontend.  The backend says 'Hello from hello-world-backend-7dfb45b98d-j8q8t (2)'.

Conclusion

As we saw in this article, Skupper comes in handy when two clusters need to be connected, and CodeReady Containers provides a great local experience for OpenShift. Happy Skuppering!

Last updated: April 19, 2021