Skip to content

Commit

Permalink
docs for kuar + kuar as yamls
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
  • Loading branch information
jkremser committed Jun 7, 2022
1 parent 1dcd834 commit 2b1edd6
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ deploy-test-apps: ## Deploy Podinfo (example app) and Apply Gslb Custom Resource
podinfo/podinfo \
--version 5.1.1

.PHONY: deploy-kuar-app
deploy-kuar-app:
./deploy/test-apps/kuar/deploy.sh $(CLUSTERS_NUMBER)

.PHONY: upgrade-candidate
upgrade-candidate: release-images deploy-test-version

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Internal k8gb architecture and its components are described [here](/docs/compone
* [AWS based deployment with Route53 integration](/docs/deploy_route53.md)
* [AWS based deployment with NS1 integration](/docs/deploy_ns1.md)
* [Local playground for testing and development](/docs/local.md)
* [Local playground with Kuar web app](/docs/local-kuar.md)
* [Metrics](/docs/metrics.md)
* [Ingress annotations](/docs/ingress_annotations.md)
* [Integration with Admiralty](/docs/admiralty.md)
Expand Down
33 changes: 33 additions & 0 deletions deploy/test-apps/kuar/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

N=${N:-$1}
N=${N:-2}
UPDATE_NGINX=${UPDATE_NGINX:-1}
DIR="${DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )}"
[[ ! "$N" =~ ^[0-9]{1,2}$ ]] && echo "error: Not a number: ${N}" >&2 && exit 1
[[ "$DEBUG" == 1 ]] && set -x

for c in $(seq 1 $N); do
echo "\nCluster ${c}:"
# deploy kuar app and svc
kubectl --context k3d-test-gslb$c -n test-gslb apply -f ${DIR}/kuar.yaml

# add custom dns server
DNS_IP=$(kubectl --context k3d-test-gslb$c get svc k8gb-coredns -n k8gb -o custom-columns='IP:spec.clusterIP' --no-headers)
kubectl --context k3d-test-gslb$c -n test-gslb patch deployment kuar \
-p "{\"spec\":{\"template\":{\"spec\":{\"dnsConfig\":{\"nameservers\":[\"${DNS_IP}\"]},\"dnsPolicy\":\"None\"}}}}"

if [ "$UPDATE_NGINX" == 1 ] ; then
# update the daemonset with nginx to use the kuar as the default backend (if no Host header is provided)
helm --kube-context=k3d-test-gslb$c -n k8gb upgrade -i nginx-ingress nginx-stable/ingress-nginx \
--version 4.0.15 -f ${DIR}/../../ingress/nginx-ingress-values.yaml \
--set controller.extraArgs.default-backend-service=test-gslb/kuar \
--set controller.extraArgs.default-server-port=8080 \
--wait --timeout=2m0s
fi

# create gslb for the app (ingress will be created)
kubectl --context k3d-test-gslb$c -n test-gslb apply -f ${DIR}/kuar_failover.yaml
done

echo "\n\nDone. Continue with opening http://localhost\n\n"
50 changes: 50 additions & 0 deletions deploy/test-apps/kuar/kuar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: kuar
name: kuar
spec:
replicas: 1
selector:
matchLabels:
app: kuar
template:
metadata:
labels:
app: kuar
spec:
containers:
- image: gcr.io/kuar-demo/kuard-amd64:blue
imagePullPolicy: Always
name: kuar
ports:
- containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /healthy
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
failureThreshold: 1
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
failureThreshold: 1

---
apiVersion: v1
kind: Service
metadata:
labels:
app: kuar
name: kuar
spec:
ports:
- port: 8080
selector:
app: kuar
File renamed without changes.
36 changes: 0 additions & 36 deletions deploy/test-apps/kuard/deploy.sh

This file was deleted.

Binary file added docs/images/kuar1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/kuar2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/kuar3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions docs/local-kuar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Local playground for testing and development

Make sure you have all the tools mentioned in [this section](./local.md#environment-prerequisites) installed.

First spin up two local k3s clusters:

```sh
make deploy-full-local-setup
```

Again, you can verify that everything is up and running by following [the steps here](./local.md#verify-installation).

## Deploy the Kuar app

```sh
make deploy-kuar-app
```

This task will deploy a simple web application called Kuar into both clusters and exposes it. It also patches the installed nginx controller to serve the app even if the `Host` header is not provided in the request. This way you can access the application in your browser under http://localhost:80 for cluster 1 and http://localhost:81 for cluster 2.

Make sure the app on http://localhost is responding, it may take a minute for the nginx ingress controller to restart with the correct parameters.

## Kuar

This application contains couple of handy features that can verify the k8gb functionality. It can resolve DNS names, simulate probe failures, can simulate a cpu intensive workload by generating RSA key pairs and also contains a simple api for queue (push & pop strings).

The make target also modified the deployment of the Kuar application to use our core dns servers. To verify that this was done, one can open the Kuar's file system browser tab and [open](http://localhost/fs/etc/resolv.conf) `/etc/resolv.conv`. It should contain the same ip as cluster-ip assigned to `k8gb-coredns` service.

Together with Kuar, we also prepared the failover gslb resource for k8gb. Where the first cluster (geotag = `eu`) is the primary one.

## Simulate failure

Before we do that, we can visit Kuar on [cluster 2](http://localhost:81) and verify that hostname `kuar.cloud.example.com` is correctly resolved IPs corresponding to nodes in the primary cluster - which is the cluster 1. This dns resolution will work the same way on both clusters, but we will be simulating the failure on cluster 1 soon so the web api will not respond on cluster 1.

![Kuar dns resolution](/docs/images/kuar1.png)

Now we can open a new tab with Kuar on cluster one and simulate the readiness probe failure for next 10 checks - http://localhost/-/readiness.

![Kuar probes](/docs/images/kuar2.png)

Once we do that, the web api on cluster 1 will become unavailable. So we can switch to the cluster two and run the web based dig again. This time it should respond with IPs from cluster two. However, once the readiness probe will start succeeding again, it will switch back to cluster 1.

![Kuar dns resolution again](/docs/images/kuar3.png)

0 comments on commit 2b1edd6

Please sign in to comment.