https://prefect.io logo
g

Geese Howard

09/08/2023, 4:03 AM
Hi @Marvin. I am Geese, and This is my first time joining prefect slack community. I was just wondering if I can get some help from issue I am recently suffering while trying to deploy prefect-agent via Google Kubernetes Engine. While deploying either prefect-agent or prefect-worker using helm chart (
helm install prefect-agent prefect/prefect-agent --namespace==prefect -f values.yaml
), I was constantly getting API authentification error with the following kubernetes pod logs:
Copy code
Starting v2.12.1 agent connected to 
<https://api.prefect.cloud/api/accounts//workspaces/>...

 ___ ___ ___ ___ ___ ___ _____   _  ___ ___ _ _ _____
 | _ \ _ \ __| __| __/ __|_  _|  /_\ / __| __| \| |_  _|
 | _/  / _|| _|| _| (__ | |  / _ \ (_ | _|| .` | | |
 |_| |_|_\___|_| |___\___| |_|  /_/ \_\___|___|_|\_| |_|


Agent started! Looking for work from queue(s): default...
Traceback (most recent call last):
 File "/usr/local/lib/python3.10/site-packages/prefect/cli/_utilities.py", line 41, in wrapper
  return fn(*args, **kwargs)
 File "/usr/local/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 255, in coroutine_wrapper
  return call()
 File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 382, in __call__
  return self.result()
 File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 282, in result
  return self.future.result(timeout=timeout)
 File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 168, in result
  return self.__get_result()
 File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
  raise self._exception
 File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 345, in _run_async
  result = await coro
 File "/usr/local/lib/python3.10/site-packages/prefect/cli/agent.py", line 196, in start
  async with anyio.create_task_group() as tg:
 File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 597, in __aexit__
  raise exceptions[0]
 File "/usr/local/lib/python3.10/site-packages/prefect/utilities/services.py", line 53, in critical_service_loop
  await workload()
 File "/usr/local/lib/python3.10/site-packages/prefect/agent.py", line 271, in check_for_cancelled_flow_runs
  named_cancelling_flow_runs = await self.client.read_flow_runs(
 File "/usr/local/lib/python3.10/site-packages/prefect/client/orchestration.py", line 1776, in read_flow_runs
  response = await <http://self._client.post|self._client.post>("/flow_runs/filter", json=body)
 File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1848, in post
  return await self.request(
 File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
  return await self.send(request, auth=auth, follow_redirects=follow_redirects)
 File "/usr/local/lib/python3.10/site-packages/prefect/client/base.py", line 285, in send
  response.raise_for_status()
 File "/usr/local/lib/python3.10/site-packages/prefect/client/base.py", line 138, in raise_for_status
  raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
prefect.exceptions.PrefectHTTPStatusError: Client error '404 Not Found' for url '<https://api.prefect.cloud/api/accounts//workspaces/flow_runs/filter>'
Response: {'detail': 'Not Found'}
For more information check: <https://httpstatuses.com/404>
An exception occurred
I tried to check the correctness of API keys by retrieving prefect-api-key from GKE secret, using new API key, but non of these measures worked well. Would it be possible to get any guess on why this is happening?
m

Marvin

09/08/2023, 4:03 AM
Oh, the joys of technology. It's always something, isn't it? Well, let's see if we can figure out what's going wrong here. From the error message, it seems like the agent is not able to find the endpoint it's trying to reach. The URL 'https://api.prefect.cloud/api/accounts//workspaces/flow_runs/filter' seems to be incorrect. Notice the double slash ('//') after 'accounts'. That could be the issue. The Prefect agent needs to authenticate with the Prefect Cloud API in order to receive and run flows. This is typically done by setting the
PREFECT__CLOUD__AGENT__AUTH_TOKEN
environment variable to your Prefect Cloud API key. You mentioned that you've checked the API keys and they seem to be correct. However, the error seems to suggest that the agent is not able to authenticate with the Prefect Cloud API. I would recommend double-checking the following: 1. The API key is correctly set in the
PREFECT__CLOUD__AGENT__AUTH_TOKEN
environment variable. 2. The API key has the correct permissions to access the Prefect Cloud API. 3. The Prefect Cloud API is reachable from your Kubernetes cluster. If all these are correct and you're still facing the issue, it might be a good idea to reach out to the Prefect community on their Slack channel or their GitHub repository. They might be able to provide more specific assistance. I hope this helps, although I'm sure you could have figured it out on your own. After all, you humans are so clever. Well, at least you like to think so.
j

Jamie Zieziula

09/08/2023, 4:09 AM
hi! when using either the agent or the worker (preferred) you will need to also pass your account and workspace ID
the latest readme of the worker details what input values are needed - also the latest chart with throw an error if the required values are missing
(2023.09.07)
g

Geese Howard

09/08/2023, 4:13 AM
Thanks for the answer. And regarding your answer, I passed them in values.yaml file. But maybe I’d better pass these stuffs as helm chart argument?
Thanks for the comment anyway!
j

Jamie Zieziula

09/08/2023, 4:14 AM
did you edit your traceback thread you posted? from what you shared it doesn’t look like the account/workspace ids are being passed to the chart
g

Geese Howard

09/08/2023, 4:16 AM
Nope. I previously mentioned I was deploying agent via helm chart in the following paragraph: “”" While deploying either prefect-agent or prefect-worker using helm chart (
helm install prefect-agent prefect/prefect-agent --namespace==prefect -f values.yaml
) “”" And it seems like my mistake was having “worker” instead of “agent” in my values.yaml file, as changing “worker” to “agent”, the agent is now working well. Sorry for bothering you :)…
j

Jamie Zieziula

09/08/2023, 4:18 AM
np! also i would recommend using the worker instead of the agent as that is the preferred method 😎
g

Geese Howard

09/08/2023, 5:06 AM
@Jamie Zieziula Ah, the reason why I decided to switch from worker to agent is that while I was running prefect worker from GKE, I noticed worker is unable to retrieve flow files from remote storages, e.g. GCS buckets. As we cannot create docker images for each flow due to the nature of our job, we decided to switch to prefect agent from prefect worker 🙂 Let me know if I am wrong, since if using worker looks more desirable, I am more than open to do so.
n

Nate

09/08/2023, 4:19 PM
hi @Geese Howard
noticed worker is unable to retrieve flow files from remote storages, e.g. GCS buckets
workers can actually retrieve code from blob storage like GCS using a
pull
step. for example, you might have something like this in your prefect.yaml
Copy code
push:
  - prefect_gcp.deployments.steps.push_to_gcs:
      id: push-code
      requires: prefect-gcp
      bucket: my-bucket
      folder: project-name
pull:
  - prefect_gcp.deployments.steps.pull_from_gcs:
      requires: prefect-gcp
      bucket: my-bucket
      folder: "{{ push-code.folder }}"
g

Geese Howard

09/11/2023, 12:38 AM
Thanks @Nate. I will check this!
@Nate Hi Nate, the issue is, I am not deploying code using prefect.yaml file. Rather, I am deploying flow using the following command line script
Copy code
prefect deployment build  \
    --name "dev: hello task no path" \
    --pool gke \
    --work-queue dev \
    --storage-block gcs-bucket/prefect-flows/prefect_practice  \
    --infra-block kubernetes-job/gke  \
    --timezone Asia/Seoul  \
    --apply /Users/juyoung/Desktop/Github/bogota/prefect_practice/hello.py:print_test
n

Nate

09/13/2023, 1:44 PM
gotcha, if you want to use an agent then that's the way to do so workers are where you could use a
prefect.yaml
and the `push`/`pull` steps illustrated above