Skip to content

Commit

Permalink
add kind selfhost
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Dec 20, 2024
1 parent 73c315e commit d43e6b5
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 3 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on: [push, pull_request]

jobs:
kind:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/src/github.com/${{ github.repository }}
- name: "Install kind"
run: |
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: "Setup k8s cluster"
run: |
cat <<EOF | kind create cluster --wait=3m --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
- name: "Print cluster details"
run: |
kubectl cluster-info
kubectl version
kubectl get pods -n kube-system
echo "current-context:" $(kubectl config current-context)
echo "environment-kubeconfig:" ${KUBECONFIG}
- name: "Install nginx ingress controller"
run: |
kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
- name: "Huly deploy"
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}/kube
run: |
kubectl apply -R -f .
kubectl wait --for=condition=Ready deployment/front --timeout 120s
kubectl wait --for=condition=Ready deployment/account --timeout 120s
kubectl wait --for=condition=Ready deployment/mongodb --timeout 120s
- name: "Check login"
run: |
token=$(curl -s -H 'Content-Type: application/json' \
-d '{"method":"createAccount","params":["user3","1234","user","1"]}' \
-X POST \
http://account.huly.example/ | jq -r '.result.token')
curl http://account.huly.example/ \
-X POST \
-d '{"method":"getUserWorkspaces","params":[]}' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H "Authorization: Bearer $token"
- name: Cleanup resources
if: ${{ success() || failure() || cancelled() }}
run: kind delete cluster
87 changes: 87 additions & 0 deletions kube/KIND.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Kind

## Install

macOS:
```bash
# For Intel Macs
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-darwin-amd64
# For M1 / ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-darwin-arm64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind
```

Linux:
```bash
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.26.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
```

## Setup cluster with port forwarding

> [!NOTE]
> On the host computer, `localhost:80` should be accessible.
```bash
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
```

Deploy ingress nginx controller:
```bash
kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml
```

Wait nginx controller to be ready:
```bash
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
```

Mount hosts:
```bash
sudo mount --bind ./hosts /etc/hosts
```


Deploy Huly with `kubectl`.

```bash
kubectl apply -R -f .
```

Wait until the front app is coming up
```bash
kubectl wait --for=condition=Ready deployment/front --timeout 120s
kubectl wait --for=condition=Ready deployment/account --timeout 120s
kubectl wait --for=condition=Ready deployment/mongodb --timeout 120s
```

Now, launch your web and and (enjoy Huly)[http://huly.example]!


## Cleanup

```bash
sudo umount -f /etc/hosts # restore original hosts file
kubectl delete -R -f . # cleanup huly resoures on the cluster
kind delete cluster # delete kind cluster
```
6 changes: 6 additions & 0 deletions kube/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This folder contains a sample configuration for Huly Kubernetes deployment.

## Requires

Requires a working kubernetes cluster with min one node. Each node should have min 2 vCPUs and 4GB of RAM.

if you don't have any k8s cluster, consider to use [kind setup](KIND.md).

## Check and update configuration

Huly deployment configuration is located in [config.yaml](config/config.yaml) and [secret.yaml](config/secret.yaml) files.
Expand Down
5 changes: 5 additions & 0 deletions kube/account/account-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ spec:
configMapKeyRef:
name: huly-config
key: MONGO_URL
- name: MONGO_URL
valueFrom:
configMapKeyRef:
name: huly-config
key: MONGO_URL
- name: SERVER_SECRET
valueFrom:
secretKeyRef:
Expand Down
7 changes: 7 additions & 0 deletions kube/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
127.0.0.1 huly.example
127.0.0.1 account.huly.example
127.0.0.1 collaborator.huly.example
127.0.0.1 huly.example
127.0.0.1 rekoni.huly.example
127.0.0.1 stats.huly.example
127.0.0.1 transactor.huly.example
1 change: 0 additions & 1 deletion kube/mongodb/mongodb-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ spec:
name: mongodb
ports:
- containerPort: 27017
hostPort: 27017
protocol: TCP
volumeMounts:
- mountPath: /data/db
Expand Down
4 changes: 2 additions & 2 deletions kube/mongodb/mongodb-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
name: mongodb
spec:
ports:
- name: "27017"
port: 27017
- port: 27017
targetPort: 27017
protocol: TCP
selector:
app: mongodb

0 comments on commit d43e6b5

Please sign in to comment.