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

Kubernetes for local dev #118

Merged
merged 85 commits into from
Jul 18, 2023
Merged

Kubernetes for local dev #118

merged 85 commits into from
Jul 18, 2023

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Jun 13, 2023

test this:

On a Linux box, download https://k3s.io/ and run it in server mode
sudo k3s kubectl create configmap otel-config --from-file=otel/collector-config.yaml
for f in deployment/*.yaml; do sudo k3s kubectl apply -f "$f"; done

On Windows, there are many ways to run Kubernetes, but the simplest way is probably to use the Kubernetes installation built into Docker Desktop. There's an "Enable Kubernetes" checkbox in the Docker settings that will do all the setup for you, though it doesn't install the kubectl binary. In order to run kubectl commands you'll need to install kubectl yourself.

UPDATE: Now partway through writing a task localdev task. Parts of it are working: you should be able to do the following:
task localdev
In another terminal, ssh k8sdev
Inside the ssh session, ls /app and you should see the Git repo

Not yet working: pushing to that Git repo and having it auto-update

@rmunn
Copy link
Contributor Author

rmunn commented Jun 14, 2023

I'm probably going to change my approach significantly: I've just learned about https://skaffold.dev/, which seems perfect for our needs. But I'm currently having a problem building the frontend Dockerfile, getting an error about "text file busy" when pnpm tries to install node-gyp. (That error is slightly misleading: it refers to trying to change a binary while that binary is being run.) Once I get that error figured out, I'll change this PR over to use Skaffold for local k8s dev.

rmunn added 11 commits June 16, 2023 10:28
Using Kubernetes from https://k3s.io/ for local development, we don't
have a weekly-snapshots-retain-4 storage class, so we need local-path.
Also, local-path doesn't allow ReadWriteMany -- but we don't need that
anyway since all of our containers are running in the same pod, and
therefore on the same node. ReadWriteMany is only required for volumes
being mounted from different nodes.
I'll put the namespace back everywhere eventually. But for local dev, we
don't (yet) need a namespace.
The `data:` key tells Kubernetes these are base64-encoded values. If
they are not encoded, the `stringData` key is correct.
These are the same values found in the .env file checked into the repo,
so this commit is not exposing any actual secrets, just the ones we use
during local development.
This creates a container that will hold the Git repo and allow us to
push to it. Next we'll set up the frontend and backend containers to
watch that repo.
The "localdev" task does everything needed to get a Git container up and
running, but does not (yet) create a .ssh/config entry for you.
This will enable us to run `skaffold dev` and have a live-reloading
version of our app running in Kubernetes.
The hasura container was being OOMKilled, so we'll try bumping its
memory allocation and its hard limit.
Long-term, we need to specify exactly which clients (e.g., the frontend
box) are allowed to connect, but AllowAnyOrigin is good enough during
dev work.
rmunn added 16 commits June 16, 2023 10:40
All k8s deployment files now use the "languagedepot" namespace. To use
that namespace by default and not have to specify `-n lanugagedepot` all
the time, add `namespace: languagedepot` to your ~/.kube/config file in
the appropriate context stanza, just after the cluster: and user: lines.
Now the login process will redirect to a server page, forcing a cookie
reload so that the rest of the app will correctly get the user from the
load() function in src/routes. This will mean that the user store should
no longer be stale.
The `crypto.subtle` module is a browser-only module; if we're doing
server-side rendering then we need the NodeJS equivalent.
Docker desktop's embedded Kubernetes doesn't have an ingress controller,
so part of local k8s dev must include deploying one. It also doesn't
have local-path storageClass, so we have to use hostpath.
Recent docker images of Node 20 have an issue where node-gyp's
postinstall step can fail because it's trying to replace a binary while
it's still running. Moving to Node 18 Docker images, just for now, to
avoid the problem.
Can't pre-hash the password if the page was SSR rendered, so as long as
we're on Node 18, we need to turn off password prehashing.
If there's a tls config block in the ingress deployment YAML, it sets
HSTS for dev.languagedepot.org even though the TLS is only configured
for staging.languagedepot.org, and that causes issues. In the future
we'll use kustomize.yaml to configure this.
Currently not working: Hasura is saying "inconsistent metadata" and
claiming that the tables Projects and Users don't exist.
Since Hasura needs the backend to be up and healthy before it will
accept its metadata, we change `wait-db` to `wait-lexbox` in the Hasura
container (and the lexbox deployment no longer waits for Hasura, but
instead waits for the database to be up and running).
This file will end up containing all PersistentVolumeClaims, so that it
can be deployed separately from skaffold
This way skaffold won't consider that it deployed the persistent volume
claims in pvc.yaml and won't clean them up after skaffold dev.
@hahn-kev
Copy link
Collaborator

hahn-kev commented Jul 5, 2023

Alright, the first time I ran it I got a weird error because I was trying to use the staging context but it couldn't connect. I changed to the docker desktop k8s context and then I get the following error:

...
#14 [builder 8/8] COPY static /app/static
#14 DONE 0.1s

#15 exporting to image
#15 exporting layers
#15 exporting layers 3.2s done
#15 writing image sha256:601fc6c0e8c9dabc0b4c75558ebae2b62c6e7bd2318ab1aa06a107470cd7d0cb done
#15 naming to ghcr.io/sillsdev/lexbox-ui:4f19dfb done
#15 DONE 3.2s
Building [ghcr.io/sillsdev/lexbox-api]...
Target platforms: [linux/amd64]
Build [ghcr.io/sillsdev/lexbox-api] was canceled
build [ghcr.io/sillsdev/lexbox-ui] failed: getting imageID for ghcr.io/sillsdev/lexbox-ui:4f19dfb: request returned Internal Server Error or API route and version http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.41/images/ghcr.io/sillsdev/lexbox-ui:4f19dfb/json, check if the server supports the requested API version

looks like it's trying to get something from docker but it can't.

To prevent a mixup of the k8s context we should probably configure skaffold to only work on the docker desktop context: https://skaffold.dev/docs/environment/kube-context/
Later on if we want to use skaffold to configure staging or prod we can but right now I just want to prevent a screwup.

Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good Robin, I left a few comments I'd like resolved before we merge in, I suspect some things might been forgotten from earlier work and are unnecessary now. Also I think I found a solution for the base/secrets issue but I'm not sure, you let me know.


FROM build AS publish
RUN dotnet publish /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/publish
RUN --mount=type=cache,target=/root/.nuget/packages dotnet publish /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/publish
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this docker file isn't used for local dev does this make any difference?

deployment/base/db-deployment.yaml Show resolved Hide resolved
deployment/base/lexbox-deployment.yaml Show resolved Hide resolved
deployment/base/lexbox-deployment.yaml Outdated Show resolved Hide resolved
deployment/base/ui-deployment.yaml Outdated Show resolved Hide resolved
deployment/localdev-deployment.yaml Outdated Show resolved Hide resolved
frontend/src/lib/user.ts Outdated Show resolved Hide resolved
deployment/base/kustomization.yaml Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

UI unit Tests

1 tests  ±0   1 ✔️ ±0   0s ⏱️ ±0s
1 suites ±0   0 💤 ±0 
1 files   ±0   0 ±0 

Results for commit 73901a5. ± Comparison against base commit c8aac3c.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jul 7, 2023

Unit Tests

8 tests  ±0   8 ✔️ ±0   10s ⏱️ -1s
3 suites ±0   0 💤 ±0 
1 files   ±0   0 ±0 

Results for commit 73901a5. ± Comparison against base commit c8aac3c.

♻️ This comment has been updated with latest results.

@hahn-kev
Copy link
Collaborator

I'm going to do my best to pick this up and carry it across the line.

@rmunn rmunn merged commit 8c76094 into develop Jul 18, 2023
7 checks passed
@hahn-kev hahn-kev deleted the chore/k8s-for-local-dev branch July 9, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change local dev to use k8s
2 participants