Skip to content

Skewer adaptation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitmodules
Empty file.
372 changes: 235 additions & 137 deletions README.md

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions skewer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
title: "PostgreSQL Example"
subtitle: "Sharing a PostgreSQL database across clusters"
github_actions_url: "https://github.com/skupperproject/skupper-example-postgresql/actions/workflows/main.yaml"
overview: |
This tutorial demonstrates how to share a PostgreSQL database across multiple Kubernetes clusters that are located in
different public and private cloud providers.
prerequisites: !string prerequisites
sites:
private1:
kubeconfig: ~/.kube/private1
namespace: private
public1:
kubeconfig: ~/.kube/public1
namespace: public1
public2:
kubeconfig: ~/.kube/public2
namespace: public2
steps:
- title: Access your clusters
preamble: !string access_your_clusters_preamble
commands:
public1:
- run: export KUBECONFIG=~/.kube/public1
public2:
- run: export KUBECONFIG=~/.kube/public2
private1:
- run: export KUBECONFIG=~/.kube/private1
- title: Set up namespaces
preamble: !string set_up_your_namespaces_preamble
commands:
public1:
- run: kubectl create namespace public1
- run: kubectl config set-context --current --namespace public1
public2:
- run: kubectl create namespace public2
- run: kubectl config set-context --current --namespace public2
private1:
- run: kubectl create namespace private1
- run: kubectl config set-context --current --namespace private1
- title: Deploy the Virtual Application Network
preamble: !string link_your_namespaces_preamble
commands:
public1:
- run: skupper init --site-name public1
- run: skupper token create --uses 2 ~/public1-token.yaml
public2:
- run: skupper init --site-name public2
- run: skupper token create ~/public2-token.yaml
- run: skupper link create ~/public1-token.yaml
- run: skupper link status --wait 30
private1:
- run: skupper init --site-name private1
- run: skupper link create ~/public1-token.yaml
- run: skupper link create ~/public2-token.yaml
- run: skupper link status --wait 30
postamble: !string link_your_namespaces_postamble
- title: Deploy the PostgreSQL service
preamble: |
After creating the application router network, deploy the PostgreSQL service.
The **private1** cluster will be used to deploy the PostgreSQL server and the **public1**
and **public2** clusters will be used to enable client communications to the server on
the **private1** cluster.
commands:
private1:
- run: mkdir pg-demo
- run: cd pg-demo
- run: git clone https://github.com/skupperproject/skupper-example-postgresql.git
- run: kubectl apply -f ~/pg-demo/skupper-example-postgresql/deployment-postgresql-svc.yaml
await: [deployment/postgresql]
- title: Create Skupper service for the Virtual Application Network
commands:
private1:
- run: skupper service create postgresql 5432
public1:
- run: skupper service status
public2:
- run: skupper service status
postamble: |
Note that the mapping for the service address defaults to `tcp`.
- title: Bind the Skupper service to the deployment target on the Virtual Application Network
commands:
private1:
- run: skupper service bind postgresql deployment postgresql
public1:
- run: skupper service status
public2:
- run: skupper service status
postamble: |
Note that the **private1** is the only cluster to provide a target.
- title: Create interactive pod with PostgreSQL client utilities
commands:
private1:
- run: "kubectl run pg-shell -i --tty --image quay.io/skupper/simple-pg --env=\"PGUSER=postgres\" --env=\"PGPASSWORD=skupper\" --env=\"PGHOST=$(kubectl get service postgresql -o=jsonpath='{.spec.clusterIP}')\" -- bash"
public1:
- run: "kubectl run pg-shell -i --tty --image quay.io/skupper/simple-pg --env=\"PGUSER=postgres\" --env=\"PGPASSWORD=skupper\" --env=\"PGHOST=$(kubectl get service postgresql -o=jsonpath='{.spec.clusterIP}')\" -- bash"
public2:
- run: "kubectl run pg-shell -i --tty --image quay.io/skupper/simple-pg --env=\"PGUSER=postgres\" --env=\"PGPASSWORD=skupper\" --env=\"PGHOST=$(kubectl get service postgresql -o=jsonpath='{.spec.clusterIP}')\" -- bash"
postamble: |
Note that if the session is ended, it can be resumed with the following:
```bash
kubectl attach pg-shell -c pg-shell -i -t
```
- title: Create a Database, Create a Table, Insert Values
preamble: |
Using the 'pg-shell' pod running on each cluster, operate on the database:
commands:
private1:
- run: createdb -e markets
public1:
- run: psql -d markets
- run: "create table if not exists product (id SERIAL, name VARCHAR(100) NOT NULL, sku CHAR(8));"
public2:
- run: psql -d markets
- run: "INSERT INTO product VALUES(DEFAULT, 'Apple, Fuji', '4131');"
- run: "INSERT INTO product VALUES(DEFAULT, 'Banana', '4011');"
- run: "INSERT INTO product VALUES(DEFAULT, 'Pear, Bartlett', '4214');"
- run: "INSERT INTO product VALUES(DEFAULT, 'Orange', '4056');"
postamble: |
From any cluster, access the `product` tables in the `markets` database to view contents.
summary: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary is rendered at the end, so this text should either go back to the start (the overview) or be recast as "what you did", not what you will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Summary updated.

In this tutorial, we have seen how to create a Virtual Application Nework that enables communications
across the public and private clusters. We deployed a PostgresSQL database
instance into a private cluster and attached it to the Virtual Application Network.
This configuration enabled the clients from different public clusters attached to the Virtual Application
Network to transparently access the database without the need of additional networking setup
(e.g. no vpn or firewall rules required).
cleaning_up:
preamble: !string cleaning_up_preamble
commands:
public1:
- run: skupper delete
- run: kubectl delete pod pg-shell
public2:
- run: skupper delete
- run: kubectl delete pod pg-shell
private1:
- run: kubectl delete pod pg-shell
- run: skupper unexpose deployment postgresql
- run: kubectl delete -f ~/pg-demo/skupper-example-postgresql/deployment-postgresql-svc.yaml
- run: skupper delete
next_steps: !string next_steps
19 changes: 19 additions & 0 deletions subrepos/skewer/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: main
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: manusa/[email protected]
with:
minikube version: 'v1.22.0'
kubernetes version: 'v1.21.2'
github token: ${{ secrets.GITHUB_TOKEN }}
- run: mkdir -p "$HOME/.local/bin"
- run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- run: echo "SKUPPER_URL=$(curl -sL https://api.github.com/repos/skupperproject/skupper/releases/latest | jq -r '.assets[] | select(.browser_download_url | contains("linux-amd64")) | .browser_download_url')" >> $GITHUB_ENV
- run: curl -sL $SKUPPER_URL | tar -C "$HOME/.local/bin" -xzf -
- run: skupper version
- run: ./plano test
2 changes: 2 additions & 0 deletions subrepos/skewer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
README.html
12 changes: 12 additions & 0 deletions subrepos/skewer/.gitrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/skupperproject/skewer
branch = main
commit = 3c2a9559fd51f392af7f9a0a78b0e1fc0535201c
parent = ae39d93b1e5a628230c89ff332974e62d70caf67
method = merge
cmdver = 0.4.3
23 changes: 23 additions & 0 deletions subrepos/skewer/.planofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from skewer import *

@command
def generate(app):
"""
Generate README.md from the data in skewer.yaml
"""
with working_dir("test-example"):
generate_readme("skewer.yaml", "README.md")
print(read("README.md"))

@command
def test(app):
with working_dir("test-example"):
generate_readme("skewer.yaml", "README.md")
check_file("README.md")
run_steps_on_minikube("skewer.yaml")

@command
def render(app):
check_program("pandoc")
run(f"pandoc -o README.html README.md")
print(f"file:{get_real_path('README.html')}")
Loading