Skip to content

Commit

Permalink
Merge pull request #1 from reside-ic/mrc-4908-k8s-setup
Browse files Browse the repository at this point in the history
Mrc-4908 k8s setup
  • Loading branch information
absternator authored Jan 31, 2024
2 parents f97a1f3 + 526208e commit 05db8b5
Show file tree
Hide file tree
Showing 26 changed files with 278 additions and 277 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/shiny-image-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build and push Shiny server image

on:
push:
branches:
- "main"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v3
- name: Build and push
run: shiny/build-and-push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
apache/ssl
k8s/ssl
60 changes: 10 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,20 @@

This is a temporary repo designed to give an easy-to-understand deployment of the apache / haproxy / shiny stack; it does not include configurable applications or anything like that. See it online at https://shiny-dev.dide.ic.ac.uk (DIDE network only).

## The components
## Running in Kubernetes

Some of these are docker images, and they are not set to pull, so you will want to rebuild. All build very quickly.
### Prerequisites

### apache
A k8s kubernetes cluster using k3s is needed to be setup first. To setup a k8s cluster follow the guide [here](https://mrc-ide.myjetbrains.com/youtrack/articles/RESIDE-A-31/Setting-up-Kubernetes-k8s-Cluster).

Running an unmodified httpd container (previously was 2.4, we'll update once we know this works). The configuration ([`apache/httpd.conf`](httpd/httpd.conf)) and certificates (`apache/ssl`) will be read-only mounted into the container. You need to fetch the ssl key and certificate, run `./apache/configure_ssl` to do this (only needs to be done if they change or if the `ssl` directory is deleted)
Run `./start-k8s-shiny <env>` to run the shiny server in k8s.

### haproxy
Note: If on testing enviroment the app will launch on the IP addr of the result of the following command:
`kubectl -n ingress-nginx get svc ingress-nginx-controller -o=jsonpath='{.status.loadBalancer.ingress[0].ip}'`

Build the image with `./haproxy/build` which builds `mrcide/haproxy` with a configuration that can be seen in [`haproxy/haproxy.cfg`](haproxy/haproxy.cfg) and some utilities which enable some degree of dynamic scaling of shiny servers.
#### Teardown

### shiny
Run the following:

A lightly modified version of the official shiny container; the original version was more extensively modified

### apps

Some applications (copied over from the original deployment are in `apps`). These will want to be in a volume; run `./apps/create_volume` to copy them into the volume

### Summary

```
./apache/configure_ssl
./haproxy/build
./shiny/build
./apps/create_volume
```

## Bringing the bits up

```
docker network create twinkle 2> /dev/null || /bin/true
docker volume create shiny_logs
docker run -d --name haproxy --network twinkle mrcide/haproxy:dev
docker run -d --name apache --network twinkle \
-p 80:80 \
-p 443:443 \
-p 9000:9000 \
-v "${PWD}/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro" \
-v "${PWD}/apache/auth:/usr/local/apache2/conf/auth:ro" \
-v "${PWD}/apache/ssl:/usr/local/apache2/conf/ssl:ro" \
httpd:2.4
docker run -d --name shiny-1 --network=twinkle \
-v twinkle_apps:/shiny/apps \
-v twinkle_logs:/shiny/logs \
-p 3838:3838 \
mrcide/shiny-server:dev
docker exec haproxy update_shiny_servers shiny 1
```

Teardown

```
docker rm -f haproxy apache shiny-1
docker network rm twinkle
```
1. `kubectl delete -k k8s/overlays/<env>`. Replace <env> with testing or production.
2. `kubectl delete ns twinkle` to remove namespace.
128 changes: 0 additions & 128 deletions apache/httpd.conf

This file was deleted.

5 changes: 0 additions & 5 deletions haproxy/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions haproxy/bin/add_server

This file was deleted.

6 changes: 0 additions & 6 deletions haproxy/bin/drop_server

This file was deleted.

17 changes: 0 additions & 17 deletions haproxy/bin/update_shiny_servers

This file was deleted.

8 changes: 0 additions & 8 deletions haproxy/build

This file was deleted.

43 changes: 0 additions & 43 deletions haproxy/haproxy.cfg

This file was deleted.

38 changes: 38 additions & 0 deletions k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shiny-deploy
labels:
app: shiny
spec:
replicas: 2
selector:
matchLabels:
app: shiny
template:
metadata:
labels:
app: shiny
spec:
initContainers:
- name: init-shiny
image: busybox:1.28
command: ["sh", "-c", "mkdir -p /shiny/logs /shiny/apps"]
volumeMounts:
- name: shiny-data
mountPath: /shiny
containers:
- name: shiny
image: mrcide/shiny-server:dev
volumeMounts:
- name: shiny-data
mountPath: /shiny
# todo: create appropriate resource requests
# resources:
# requests:
# memory: "128Mi"
# cpu: "250m"
volumes:
- name: shiny-data
persistentVolumeClaim:
claimName: shiny-pvc
21 changes: 21 additions & 0 deletions k8s/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-shiny
annotations:
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "shinycookie"
nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: shiny-svc
port:
number: 3838
12 changes: 12 additions & 0 deletions k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
name: shiny

namespace: twinkle # assume this namespace exists

resources:
- persistence.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
Loading

0 comments on commit 05db8b5

Please sign in to comment.