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

bee-hive in kubernetes #163

Merged
merged 8 commits into from
Feb 3, 2025
Merged

Conversation

akihikokuroda
Copy link
Collaborator

@akihikokuroda akihikokuroda commented Jan 31, 2025

This PR makes Bee-hive deployable and accessible in kubernetes.

A small API is added bee-hive image. It accepts request with 2 yaml files and runs workflow.
This PR has kubernetes deployment and service (it's using a NodePort right now) yaml files. The can be deployed with the kubectl. The bee-hive with container runtime is also adjusted to use the API instead of mounting the local file system.

The bee-hive.sh has 4 commands (the first argument)

  • build: build container image
  • deploy: deploy bee-hive in container service
  • deploy-k: deploy bee-hive in kubernetes
  • run: run the work flow in the environment

Run workflow in local environment with container runtime (e.g. podman) or kubernetes cluster

  • Prepare required environments

    • Run a local instance of the Bee Stack
    • curl is required for run command
    • for Kubernetes, kubectl and sed are required
  • Build bee-hive container image: ./bee-hive.sh build in bee-hive/bee-hive directory

  • Deploy bee-hive: ./bee-hive.sh deploy BEE_API=http://xxx.xxx.xxx.xxx:4000 BEE_API_KEY=sk-proj-testkey

    • To deploy to kubernetes cluster, user deploy-k instead deploy as the first argument
    • The required environment variables can be provided at the end of command arguments (e.g. BEE_API=http://192.168.86.45:4000).
  • Prepare agent and workflow definition yaml files in the current directory (e.g. agent.yaml, workflow.yaml)

  • Run workflow: ./bee-hive.sh run agents.yaml workflow.yaml

@akihikokuroda akihikokuroda marked this pull request as draft January 31, 2025 13:25
@akihikokuroda akihikokuroda marked this pull request as ready for review January 31, 2025 20:29
@psschwei
Copy link
Collaborator

Local deploy works as expected.
Checking Kubernetes deploy-k now.

@akihikokuroda akihikokuroda changed the title [WIP] bee-hive in kubernetes bee-hive in kubernetes Jan 31, 2025
@akihikokuroda
Copy link
Collaborator Author

@psschwei They are using same local port number. You may need to stop the docker container first.

@psschwei
Copy link
Collaborator

psschwei commented Jan 31, 2025

Kubernetes is failing for me with an "unable to create agents" error. Partial stack trace

Traceback (most recent call last):
  File "/usr/src/app/api.py", line 49, in process_workflow
    workflow_instance = Workflow(agents_yaml, workflow_yaml[0])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/bee_hive/workflow.py", line 47, in __init__
    self.agents[agent_def["metadata"]["name"]] = get_agent_class(
                                                 ^^^^^^^^^^^^^^^^
  File "/usr/src/app/bee_hive/bee_agent.py", line 43, in __init__
    assistant = client.beta.assistants.create(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/resources/beta/assistants.py", line 149, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1283, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 960, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1005, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1098, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1005, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1098, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/openai/_base_client.py", line 1015, in _request
    raise APITimeoutError(request=request) from err
openai.APITimeoutError: Request timed out.


@psschwei
Copy link
Collaborator

psschwei commented Jan 31, 2025

I wonder if the problem is my Kubernetes not being able to talk to the bee-stack 🤔 ... (I'm using kind)

@akihikokuroda
Copy link
Collaborator Author

@psschwei Does the deployment get the correct environment variables?

@maximilien
Copy link
Collaborator

Thank you so much for this @akihikokuroda and will spend some time on this but don't let me slow you down

@psschwei is reviewing and if he reaches LGTM before I get to review then push forward and merge and I will catch up. This is v1 of a very important feature.

どうもありがとうございます

@akihikokuroda
Copy link
Collaborator Author

@psschwei I tried with kind and it is working. I changed the bee-hive.yaml at the last minutes. You might not pick up the change.

Copy link
Collaborator

@psschwei psschwei left a comment

Choose a reason for hiding this comment

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

awesome! I was able to run without issue.

I have one minor comment on the readme (which could be fixed now or in a followon PR), but otherwise LGTM

Comment on lines +112 to +113
* Deploy bee-hive: `./bee-hive.sh deploy BEE_API=http://xxx.xxx.xxx.xxx:4000 BEE_API_KEY=sk-proj-testkey`
* To deploy to kubernetes cluster, user `deploy-k` instead `deploy` as the first argument
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: let's make two sections for the deploy, one for docker and one for kubernetes. that would also allow for including some kubernetes-specific instructions:

  • to load the image into the cluster
  • to port-forward the bee-hive service, if necessary

since both of those will differ depending on the k8s used (rancher, kind, etc.), I don't think we need to include specific instructions, but we should mention that the steps are needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@psschwei Thanks! I'll create another PR for the readme update!

Copy link
Collaborator

Choose a reason for hiding this comment

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

feel free to merge when you're ready (or if you want to wait to see if anyone has comments that's cool too)

@akihikokuroda akihikokuroda merged commit 03962c7 into i-am-bee:main Feb 3, 2025
1 check passed
@akihikokuroda akihikokuroda deleted the remotehive branch February 3, 2025 17:35
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.

3 participants