Skip to content
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

feat(new-demo): use the new kuma-counter-demo #2104

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/styles/config/vocabularies/Base/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ kubectl
kumactl
kustomization
Kustomize
kv
linkStyle
Loggly
loopback
Expand Down
94 changes: 22 additions & 72 deletions app/_src/guides/gateway-builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ flowchart LR
subgraph edge-gateway
gw0(/ :8080)
end
demo-app(demo-app :5000)
redis(redis :6379)
demo-app(demo-app :5050)
kv(`kv` :5050)
gw0 --> demo-app
demo-app --> redis
demo-app --> kv
{% endmermaid %}

## Prerequisites
- Completed [quickstart](/docs/{{ page.release }}/quickstart/kubernetes-demo/) to set up a zone control plane with demo application

{% tip %}
running `kubectl apply -f kuma-demo://k8s/001-with-mtls.yaml`
will set up the equivalent of the quickstart with TLS enabled.
{% endtip %}

## Start a gateway

### Create a `MeshGatewayInstance`
Expand All @@ -36,14 +41,7 @@ that will run the gateway.

Create it by running:
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshGatewayInstance
metadata:
name: edge-gateway
namespace: kuma-demo
spec:
replicas: 1
serviceType: LoadBalancer" | kubectl apply -f -
kubectl apply -f kuma-demo://kustomize/overlays/002-with-gateway/mesh-gateway-instance.yaml
```

{% warning %}
Expand All @@ -62,21 +60,7 @@ One option for `kind` is [kubernetes-sigs/cloud-provider-kind](https://github.co
Define a single HTTP listener on port 8080:

```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: my-gateway
spec:
selectors:
- match:
kuma.io/service: edge-gateway_kuma-demo_svc
conf:
listeners:
- port: 8080
protocol: HTTP
tags:
port: http-8080" | kubectl apply -f -
kubectl apply -f kuma-demo://kustomize/overlays/002-with-gateway/mesh-gateway.yaml
```

Notice how the selector selects the `kuma.io/service` tag of the previously defined `MeshGatewayInstance`.
Expand Down Expand Up @@ -142,7 +126,7 @@ metadata:
spec:
targetRef:
kind: MeshGateway
name: my-gateway
name: edge-gateway
to:
- targetRef:
kind: Mesh
Expand All @@ -158,33 +142,15 @@ spec:
```
{% endif_version %}
{% if_version gte:2.9.x %}
{% if site.mesh_namespace != "kuma-system" %}
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
metadata:
name: edge-gateway-route
namespace: {{site.mesh_namespace}}
labels:
kuma.io/mesh: default
spec:
targetRef:
kind: MeshGateway
name: my-gateway
to:
- targetRef:
kind: Mesh
rules:
- matches:
- path:
type: PathPrefix
value: "/"
default:
backendRefs:
- kind: MeshService
name: demo-app
namespace: kuma-demo
port: 5000" | kubectl apply -f -
curl -s kuma-demo://kustomize/overlays/002-with-gateway/mesh-http-route.yaml | sed 's/kuma-system/{{ site.mesh_namespace }}/g' | kubectl apply -f -
```
{% else %}
```sh
kubectl apply -f kuma-demo://kustomize/overlays/002-with-gateway/mesh-http-route.yaml
```
{% endif %}
{% endif_version %}

Now try to reach our gateway again:
Expand Down Expand Up @@ -240,29 +206,13 @@ spec:
{% endif_version %}
{% if_version gte:2.9.x %}
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshTrafficPermission
metadata:
namespace: kuma-demo
name: demo-app
spec:
targetRef:
kind: MeshSubset
tags:
app: demo-app
from:
- targetRef:
kind: MeshSubset
tags:
kuma.io/service: edge-gateway_kuma-demo_svc
default:
action: Allow" | kubectl apply -f -
kubectl apply -f kuma-demo://kustomize/overlays/002-with-gateway/mesh-traffic-permission.yaml
```
{% endif_version %}

Check it works with:
```sh
curl -XPOST -v ${PROXY_IP}:8080/increment
curl -XPOST -v ${PROXY_IP}:8080/api/counter
```

Now returns a 200 OK response:
Expand Down Expand Up @@ -320,7 +270,7 @@ echo "apiVersion: kuma.io/v1alpha1
kind: MeshGateway
mesh: default
metadata:
name: my-gateway
name: edge-gateway
spec:
selectors:
- match:
Expand All @@ -339,7 +289,7 @@ spec:

Check the call to the gateway:
```sh
curl -X POST -v --insecure "https://${PROXY_IP}:8080/increment"
curl -X POST -v --insecure "https://${PROXY_IP}:8080/api/counter"
```

Which should output a successful call and indicate TLS is being used:
Expand Down
20 changes: 13 additions & 7 deletions app/_src/guides/gateway-delegated.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ flowchart LR
subgraph Kong Gateway
gw0(/ :80)
end
demo-app(demo-app :5000)
redis(redis :6379)
demo-app(demo-app :5050)
kv(kv :5050)
gw0 --> demo-app
demo-app --> redis
demo-app --> kv
{% endmermaid %}

## Prerequisites
- Completed [quickstart](/docs/{{ page.release }}/quickstart/kubernetes-demo/) to set up a zone control plane with demo application

{% tip %}
running `kubectl apply -f kuma-demo://k8s/001-with-mtls.yaml`
will set up the equivalent of the quickstart with TLS enabled.
{% endtip %}

## Install Kong ingress controller

Follow the steps on the [Kong docs website](https://docs.konghq.com/kubernetes-ingress-controller/latest/get-started/) to install the ingress controller.
Expand Down Expand Up @@ -122,8 +127,9 @@ spec:
value: /
backendRefs:
- name: demo-app
namespace: kuma-demo
kind: Service
port: 5000 " | kubectl apply -f -
port: 5050 " | kubectl apply -f -
```

{% warning %}
Expand Down Expand Up @@ -205,7 +211,7 @@ spec:

Call the gateway again:
```sh
curl -i $PROXY_IP/increment -XPOST
curl -i $PROXY_IP/api/counter -XPOST
```

Notice that the call succeeds:
Expand All @@ -215,7 +221,7 @@ HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 41
Connection: keep-alive
x-powered-by: Express
x-demo-app-version: v1
etag: W/"29-iu9zuSv48n703xjnEeBnBQzQFgA"
date: Fri, 09 Feb 2024 15:57:27 GMT
x-envoy-upstream-service-time: 7
Expand All @@ -225,7 +231,7 @@ X-Kong-Proxy-Latency: 0
Via: kong/3.5.0
X-Kong-Request-Id: 886cc96df034ea37cfbbb0450a987049

{"counter":149,"zone":"local","err":null}%
{"counter":149,"zone":""}%
```

## Next steps
Expand Down
62 changes: 20 additions & 42 deletions app/_src/quickstart/kubernetes-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ title: Deploy Kuma on Kubernetes

To start learning how {{site.mesh_product_name}} works, you run and secure a simple demo application that consists of two services:

- `demo-app`: a web application that lets you increment a numeric counter. It listens on port 5000
- `redis`: data store for the counter
- `demo-app`: a web application that lets you increment a numeric counter. It listens on port 5050
- `kv`: an in-memory http database that lets you increment a numeric counter. It listens on port 5050


{% mermaid %}
---
title: service graph of the demo app
---
flowchart LR
demo-app(demo-app :5000)
redis(redis :6379)
demo-app --> redis
demo-app(demo-app :5050)
kv(kv :5050)
demo-app --> kv
{% endmermaid %}


Expand Down Expand Up @@ -50,17 +50,22 @@ helm install --create-namespace --namespace {{site.mesh_namespace}} {{ site.mesh

1. Deploy the application
```sh
kubectl apply -f https://raw.githubusercontent.com/kumahq/kuma-counter-demo/master/demo.yaml
kubectl apply -f kuma-demo://k8s/000-with-kuma.yaml
kubectl wait -n kuma-demo --for=condition=ready pod --selector=app=demo-app --timeout=90s
```

2. Port-forward the service to the namespace on port 5000:

```sh
kubectl port-forward svc/demo-app -n kuma-demo 5000:5000
kubectl port-forward svc/demo-app -n kuma-demo 5050:5050
```

3. In a browser, go to [127.0.0.1:5000](http://127.0.0.1:5000) and increment the counter.
3. In a browser, go to [127.0.0.1:5050](http://127.0.0.1:5050) and increment the counter.

{% tip %}
You can also use the command line `curl -XPOST localhost:5050/api/counter` or play with the demo [in Insomnia](https://insomnia.rest/run/?label=kuma-counter-demo&uri=https%3A%2F%2Fgithub.com%2Fkumahq%2Fkuma-counter-demo%2Fblob%2F{{ site.mesh_demo_version }}%2Fopenapi.yaml).
{% endtip %}


The demo app includes the `kuma.io/sidecar-injection` label enabled on the `kuma-demo` namespace.

Expand Down Expand Up @@ -117,18 +122,7 @@ spec:
{% endif_version %}
{% if_version gte:2.9.x %}
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: Mesh
metadata:
name: default
spec:
meshServices:
mode: Exclusive
mtls:
enabledBackend: ca-1
backends:
- name: ca-1
type: builtin" | kubectl apply -f -
kubectl patch mesh default --type merge --patch "$(curl kuma-demo://kustomize/overlays/001-with-mtls/mesh.yaml)"
```
{% endif_version %}

Expand All @@ -138,53 +132,37 @@ means that no traffic will flow with mTLS enabled until we define a proper [Mesh

For now, the demo application won't work.
You can verify this by clicking the increment button again and seeing the error message in the browser.
We can allow the traffic from the `demo-app` to `redis` by applying the following `MeshTrafficPermission`:
We can allow the traffic from the `demo-app` to `kv` by applying the following `MeshTrafficPermission`:

{% if_version lte:2.8.x %}
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshTrafficPermission
metadata:
namespace: {{site.mesh_namespace}}
name: redis
name: kv
spec:
targetRef:
kind: MeshSubset
tags:
kuma.io/service: redis_kuma-demo_svc_6379
kuma.io/service: kv_kuma-demo_svc_5050
from:
- targetRef:
kind: MeshSubset
tags:
kuma.io/service: demo-app_kuma-demo_svc_5000
kuma.io/service: demo-app_kuma-demo_svc_5050
default:
action: Allow" | kubectl apply -f -
```
{% endif_version %}
{% if_version gte:2.9.x %}
```sh
echo "apiVersion: kuma.io/v1alpha1
kind: MeshTrafficPermission
metadata:
namespace: kuma-demo
name: redis
spec:
targetRef:
kind: MeshSubset
tags:
app: redis
from:
- targetRef:
kind: MeshSubset
tags:
kuma.io/service: demo-app_kuma-demo_svc_5000
default:
action: Allow" | kubectl apply -f -
kubectl apply -f kuma-demo://kustomize/overlays/001-with-mtls/mesh-traffic-permission.yaml
```
{% endif_version %}

You can click the increment button, the application should function once again.
However, the traffic to `redis` from any other service than `demo-app` is not allowed.
However, the traffic to `kv` from any other service than `demo-app` is not allowed.

## Next steps

Expand Down
2 changes: 2 additions & 0 deletions jekyll-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ mesh_helm_repo_url: https://kumahq.github.io/charts
mesh_helm_repo_name: kuma
mesh_helm_repo: kuma/kuma
mesh_helm_install_name: kuma
# Can be used for WIP demos
# mesh_demo_version: skaffold-kustomize

# binary options
mesh_install_archive_name: kuma
Expand Down
2 changes: 1 addition & 1 deletion jekyll-kuma-plugins/lib/jekyll/kuma-plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
require_relative 'kuma-plugins/liquid/tags/cpinstall'
require_relative 'kuma-plugins/liquid/tags/cpinstallfile'
require_relative 'kuma-plugins/liquid/tags/inc'
require_relative 'kuma-plugins/liquid/blocks/helmvalues'
require_relative 'kuma-plugins/generators/demourl'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Jekyll
module KumaPlugins
class Generator < Jekyll::Generator
priority :lowest

def generate(site)
demo_version = site.config.fetch('mesh_demo_version', 'main')
site.pages.each do |page|
page.content = page.content.gsub("kuma-demo://", "https://raw.githubusercontent.com/kumahq/kuma-counter-demo/refs/heads/#{demo_version}/")
end
end
end
end
end
Loading