Questo contenuto non è disponibile nella lingua selezionata.
Chapter 2. Skupper Hello World
A minimal HTTP application deployed across Kubernetes clusters using Skupper
This example is part of a suite of examples showing the different ways you can use Skupper to connect services across cloud providers, data centers, and edge sites.
Overview
This example is a very simple multi-service HTTP application deployed across Kubernetes clusters using Skupper.
It contains two services:
-
A backend service that exposes an
/api/helloendpoint. It returns greetings of the formHi, <your-name>. I am <my-name> (<pod-name>). - A frontend service that sends greetings to the backend and fetches new greetings in response.
With Skupper, you can place the backend in one cluster and the frontend in another and maintain connectivity between the two services without exposing the backend to the public internet.
Prerequisites
-
The
kubectlcommand-line tool, version 1.15 or later (installation guide) - Access to at least one Kubernetes cluster, from any provider you choose
Procedure
- Clone the repo for this example.
- Install the Skupper command-line tool
- Set up your clusters
- Deploy the frontend and backend
- Create your sites
- Link your sites
- Expose the backend
- Clone the repo for this example. Navigate to the appropriate GitHub repository from https://skupper.io/examples/index.html and clone the repository.
Install the Skupper command-line tool
This example uses the Skupper command-line tool to deploy Skupper. You need to install the
skuppercommand only once for each development environment.See the Installation for details about installing the CLI. For configured systems, use the following command:
sudo dnf install skupper-cliSet up your clusters
Skupper is designed for use with multiple Kubernetes clusters. The
skupperandkubectlcommands use your kubeconfig and current context to select the cluster and namespace where they operate.Your kubeconfig is stored in a file in your home directory. The
skupperandkubectlcommands use theKUBECONFIGenvironment variable to locate it.A single kubeconfig supports only one active context per user. Since you will be using multiple contexts at once in this exercise, you need to create distinct kubeconfigs.
For each namespace, open a new terminal window. In each terminal, set the
KUBECONFIGenvironment variable to a different path and log in to your cluster. Then create the namespace you wish to use and set the namespace on your current context.NoteThe login procedure varies by provider. See the documentation for yours:
West:
export KUBECONFIG=~/.kube/config-west # Enter your provider-specific login command kubectl create namespace west kubectl config set-context --current --namespace westEast:
export KUBECONFIG=~/.kube/config-east # Enter your provider-specific login command kubectl create namespace east kubectl config set-context --current --namespace eastDeploy the frontend and backend
This example runs the frontend and the backend in separate Kubernetes namespaces, on different clusters.
Use
kubectl create deploymentto deploy the frontend in West and the backend in East.West:
kubectl create deployment frontend --image quay.io/skupper/hello-world-frontendEast:
kubectl create deployment backend --image quay.io/skupper/hello-world-backend --replicas 3Create your sites
A Skupper site is a location where components of your application are running. Sites are linked together to form a network for your application. In Kubernetes, a site is associated with a namespace.
For each namespace, use
skupper initto create a site. This deploys the Skupper router and controller. Then useskupper statusto see the outcome.West:
skupper init skupper statusSample output:
$ skupper init Waiting for LoadBalancer IP or hostname... Waiting for status... Skupper is now installed in namespace 'west'. Use 'skupper status' to get more information. $ skupper status Skupper is enabled for namespace "west". It is not connected to any other sites. It has no exposed services.East:
skupper init skupper statusSample output:
$ skupper init Waiting for LoadBalancer IP or hostname... Waiting for status... Skupper is now installed in namespace 'east'. Use 'skupper status' to get more information. $ skupper status Skupper is enabled for namespace "east". It is not connected to any other sites. It has no exposed services.As you move through the steps below, you can use
skupper statusat any time to check your progress.Link your sites
A Skupper link is a channel for communication between two sites. Links serve as a transport for application connections and requests.
Creating a link requires use of two
skuppercommands in conjunction,skupper token createandskupper link create.The
skupper token createcommand generates a secret token that signifies permission to create a link. The token also carries the link details. Then, in a remote site, Theskupper link createcommand uses the token to create a link to the site that generated it.NoteThe link token is truly a secret. Anyone who has the token can link to your site. Make sure that only those you trust have access to it.
First, use
skupper token createin West to generate the token. Then, useskupper link createin East to link the sites.West:
skupper token create ~/secret.tokenSample output:
$ skupper token create ~/secret.token Token written to ~/secret.tokenEast:
skupper link create ~/secret.tokenSample output:
$ skupper link create ~/secret.token Site configured to link to https://10.105.193.154:8081/ed9c37f6-d78a-11ec-a8c7-04421a4c5042 (name=link1) Check the status of the link using 'skupper link status'.If your terminal sessions are on different machines, you may need to use
scpor a similar tool to transfer the token securely. By default, tokens expire after a single use or 15 minutes after creation.Expose the backend
We now have our sites linked to form a Skupper network, but no services are exposed on it. Skupper uses the
skupper exposecommand to select a service from one site for exposure in all the linked sites.Use
skupper exposeto expose the backend service in East to the frontend in West.East:
skupper expose deployment/backend --port 8080Sample output:
$ skupper expose deployment/backend --port 8080 deployment backend exposed as backendAccess the frontend
In order to use and test the application, we need external access to the frontend.
Use
kubectl port-forwardto make the frontend available atlocalhost:8080.West:
kubectl port-forward deployment/frontend 8080:8080You can now access the web interface by navigating to http://localhost:8080 in your browser.