Skip to content

Instantly share code, notes, and snippets.

@jpeach
Created December 8, 2021 04:39
Show Gist options
  • Save jpeach/5b757b17cdd0ca90589bac3d511bfadf to your computer and use it in GitHub Desktop.
Save jpeach/5b757b17cdd0ca90589bac3d511bfadf to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -o errexit
readonly ENVOY=${ENVOY:-${HOME}/.getenvoy/versions/1.18.3/bin/envoy}
readonly DPTYPE=dataplane
exec kuma-dp run \
--binary-path=$ENVOY \
--dataplane-token=$(kumactl generate dataplane-token --proxy-type=${DPTYPE}) \
--proxy-type=${DPTYPE} \
--dataplane-file=<(
cat <<EOF
type: Dataplane
mesh: default
name: greenling
networking:
address: 127.0.0.1
gateway:
type: BUILTIN
tags:
kuma.io/service: edge-gateway
EOF
) "$@"
#! /usr/bin/env bash
set -o errexit
clean::name() {
echo "$@" | tr --delete --complement '[0-9a-z]_-'
}
kill::tagged() {
kill -TERM $(ps e | grep --fixed-strings -e "KILLTAG=$KILLTAG" | awk '{print $1}') 2>/dev/null
}
readonly ENVOY=${ENVOY:-${HOME}/.getenvoy/versions/1.18.3/bin/envoy}
readonly KILLTAG="$(basename $0)-$RANDOM"
readonly NAME=$(clean::name $(basename $0))
trap kill::tagged EXIT
kumactl apply -f <(
cat <<EOF
type: Dataplane
mesh: default
name: $NAME
networking:
address: 127.0.0.1
inbound:
- port: 20011
servicePort: 10011
tags:
kuma.io/service: echo-service
EOF
)
env KILLTAG=$KILLTAG \
test-server echo --instance="$(basename $0)-$$" --port=10011 &
env KILLTAG=$KILLTAG \
kuma-dp run \
--binary-path=$ENVOY \
--dataplane-token=$(kumactl generate dataplane-token --proxy-type=dataplane) \
--proxy-type=dataplane \
--mesh=default \
--name=$NAME \
"$@" &
wait
#! /usr/bin/env bash
set -o errexit
kumactl apply -f <(
cat <<EOF
type: Mesh
name: default
mtls:
enabledBackend: builtin
backends:
- name: builtin
type: builtin
EOF
)
#! /usr/bin/env bash
set -o errexit
kumactl apply -f <(
cat <<EOF
type: Gateway
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
name: foo.example.com
EOF
)
#! /usr/bin/env bash
set -o errexit
kumactl apply -f <(
cat <<EOF
type: Gateway
mesh: default
name: edge-gateway
sources:
- match:
kuma.io/service: edge-gateway
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: foo.example.com
tags:
name: foo.example.com
- port: 8080
protocol: HTTP
hostname: bar.example.com
tags:
name: bar.example.com
EOF
)
#! /usr/bin/env bash
set -o errexit
kumactl apply -f <(
cat <<EOF
type: GatewayRoute
mesh: default
name: edge-gateway
selectors:
- match:
kuma.io/service: edge-gateway
conf:
http:
rules:
- matches:#! /usr/bin/env bash
set -o errexit
readonly SERVICENAME=${SERVICENAME:-edge-gateway}
echo Creating external service
kumactl apply -f <(
cat <<EOF
type: ExternalService
mesh: default
name: httpbin
tags:
kuma.io/service: httpbin
kuma.io/protocol: http
networking:
address: httpbin.org:443
tls:
enabled: true
sni: httpbin.org
EOF
)
echo Creating gateway
kumactl apply -f <(
cat <<EOF
type: Gateway
mesh: default
name: httpbin-gateway
selectors:
- match:
kuma.io/service: ${SERVICENAME}
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: 'zero.example.com'
tags:
name: example.com
- port: 8081
protocol: HTTP
hostname: 'one.example.com'
tags:
name: example.com
EOF
)
echo Creating routes
kumactl apply -f <(
cat <<EOF
type: GatewayRoute
mesh: default
name: httpbin-routes
selectors:
- match:
kuma.io/service: ${SERVICENAME}
conf:
http:
rules:
- matches:
- path:
match: PREFIX
value: /
backends:
- destination:
kuma.io/service: httpbin
EOF
)
- path:
match: PREFIX
value: /
backends:
- destination:
kuma.io/service: echo-service
EOF
)
#! /usr/bin/env bash
set -o errexit
readonly SERVICENAME=${SERVICENAME:-edge-gateway}
echo Creating external service
kumactl apply -f <(
cat <<EOF
type: ExternalService
mesh: default
name: httpbin
tags:
kuma.io/service: httpbin
kuma.io/protocol: http
networking:
address: httpbin.org:443
tls:
enabled: true
sni: httpbin.org
EOF
)
echo Creating gateway
kumactl apply -f <(
cat <<EOF
type: Gateway
mesh: default
name: httpbin-gateway
selectors:
- match:
kuma.io/service: ${SERVICENAME}
conf:
listeners:
- port: 8080
protocol: HTTP
hostname: 'zero.example.com'
tags:
name: example.com
- port: 8081
protocol: HTTP
hostname: 'one.example.com'
tags:
name: example.com
EOF
)
echo Creating routes
kumactl apply -f <(
cat <<EOF
type: GatewayRoute
mesh: default
name: httpbin-routes
selectors:
- match:
kuma.io/service: ${SERVICENAME}
conf:
http:
rules:
- matches:
- path:
match: PREFIX
value: /
backends:
- destination:
kuma.io/service: httpbin
EOF
)
@michaelbeaumont
Copy link

Let's get this in a repo somewhere.

I think something went wrong here:

https://gist.github.com/jpeach/5b757b17cdd0ca90589bac3d511bfadf#file-06-gatewayroute-sh-L16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment