Zach Hodowanec
05/11/2021, 10:59 PMprefect --help
results.Zach Hodowanec
05/11/2021, 10:59 PMapiVersion: batch/v1
kind: Job
metadata:
name: prefect-job-spec
labels: {}
spec:
template:
metadata:
labels: {}
spec:
restartPolicy: Never
containers:
- name: flow
image: prefecthq/prefect:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c"]
args: ["prefect execute flow-run"]
env:
- name: PREFECT__LOGGING__LEVEL
value: "INFO"
- name: PREFECT__CLOUD__USE_LOCAL_SECRETS
value: "false"
- name: PREFECT__ENGINE__FLOW_RUNNER__DEFAULT_CLASS
value: "prefect.engine.cloud.CloudFlowRunner"
- name: PREFECT__ENGINE__TASK_RUNNER__DEFAULT_CLASS
value: "prefect.engine.cloud.CloudTaskRunner"
volumeMounts:
- name: secret-volume
mountPath: /etc/secret-volume
readOnly: true
volumes:
- name: secret-volume
secret:
secretName: prefect-secret
Zach Hodowanec
05/11/2021, 11:00 PM<http://prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/identifier=xxxxxxxx|prefect.io/identifier=xxxxxxxx>
Zach Hodowanec
05/11/2021, 11:05 PMUsage: prefect [OPTIONS] COMMAND [ARGS]...
The Prefect CLI for creating, managing, and inspecting your flows.
Note: a Prefect Cloud API token is required for all Cloud related commands. If a token
is not set then run `prefect auth login` to set it.
Query Commands:
get List high-level object information
describe Retrieve detailed object descriptions
Action Commands:
agent Manage agents
create Create objects
delete Delete objects
execute Execute a flow's environment
run Run a flow
register Register flows with an API
heartbeat Send heartbeats for a run
Setup Commands:
auth Handle Prefect Cloud authorization
backend Switch between `server` and `cloud` backends
server Interact with the Prefect Server
Miscellaneous Commands:
version Print the current Prefect version
config Output Prefect config
diagnostics Output Prefect diagnostic information
Options:
-h, --help Show this message and exit.
Commands:
agent Manage Prefect agents.
build Build one or more flows.
register Register one or more flows into a project
Kevin Kho
Kevin Kho
Zach Hodowanec
05/12/2021, 1:22 AM--show-flow-logs
as well as setting PREFECT__LOGGING__LEVEL = DEBUG
. Unfortunately, I get the same prefect --help
results I posted previously. I see no evidence that my flow ever actually starts it's execution.Kevin Kho
Zach Hodowanec
05/12/2021, 1:26 AM0.14.17
Tyler Wanner
05/12/2021, 4:06 PMprefect
and not prefect execute flow-run
Zach Hodowanec
05/12/2021, 5:43 PMprefect
but can confirm the created job definition does in fact include the execute flow-run
args as well.
Here's a clip from the pod for my job:
Name: prefect-job-e3b61173-fgzfh
Namespace: prefect-demo
Priority: 0
Node: docker-desktop/xxx.xxx.xx.x
Start Time: Wed, 12 May 2021 11:34:13 -0600
Labels: <http://app.kubernetes.io/instance=prefect-agent|app.kubernetes.io/instance=prefect-agent>
<http://app.kubernetes.io/managed-by=Helm|app.kubernetes.io/managed-by=Helm>
<http://app.kubernetes.io/name=prefect-agent|app.kubernetes.io/name=prefect-agent>
<http://app.kubernetes.io/version=0.14.17-python3.8|app.kubernetes.io/version=0.14.17-python3.8>
controller-uid=a8ded4b8-e0b5-4aa4-8b10-523b3fea5981
<http://helm.sh/chart=prefect-agent-0.1.0-dev|helm.sh/chart=prefect-agent-0.1.0-dev>
job-name=prefect-job-e3b61173
<http://prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/identifier=xxxxxxxx|prefect.io/identifier=xxxxxxxx>
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: Job/prefect-job-e3b61173
Containers:
flow:
Container ID:
Image: prefecthq/prefect:0.14.17-python3.8
Image ID:
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
Args:
prefect
execute
flow-run
Zach Hodowanec
05/12/2021, 5:45 PMZach Hodowanec
05/12/2021, 10:27 PMName: prefect-job-xxxxxxxx
Namespace: prefect-deploy-keys
Selector: controller-uid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Labels: <http://app.kubernetes.io/instance=prefect-agent|app.kubernetes.io/instance=prefect-agent>
<http://app.kubernetes.io/managed-by=Helm|app.kubernetes.io/managed-by=Helm>
<http://app.kubernetes.io/name=prefect-agent|app.kubernetes.io/name=prefect-agent>
<http://app.kubernetes.io/version=0.14.17-python3.8|app.kubernetes.io/version=0.14.17-python3.8>
<http://helm.sh/chart=prefect-agent-0.1.0-dev|helm.sh/chart=prefect-agent-0.1.0-dev>
<http://prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/identifier=xxxxxxxx|prefect.io/identifier=xxxxxxxx>
Annotations: <none>
Parallelism: 1
Completions: 1
Start Time: Wed, 12 May 2021 16:03:17 -0600
Pods Statuses: 1 Running / 0 Succeeded / 0 Failed
Pod Template:
Labels: <http://app.kubernetes.io/instance=prefect-agent|app.kubernetes.io/instance=prefect-agent>
<http://app.kubernetes.io/managed-by=Helm|app.kubernetes.io/managed-by=Helm>
<http://app.kubernetes.io/name=prefect-agent|app.kubernetes.io/name=prefect-agent>
<http://app.kubernetes.io/version=0.14.17-python3.8|app.kubernetes.io/version=0.14.17-python3.8>
controller-uid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<http://helm.sh/chart=prefect-agent-0.1.0-dev|helm.sh/chart=prefect-agent-0.1.0-dev>
job-name=prefect-job-xxxxxxxx
<http://prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/identifier=xxxxxxxx|prefect.io/identifier=xxxxxxxx>
Containers:
flow:
Image: prefecthq/prefect:latest
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
Args:
prefect
execute
flow-run
Environment:
PREFECT__LOGGING__LEVEL: INFO
PREFECT__BACKEND: cloud
PREFECT__CLOUD__AGENT__LABELS: ['my-label']
PREFECT__CLOUD__API: <https://api.prefect.io>
PREFECT__CLOUD__AUTH_TOKEN: ****
PREFECT__CLOUD__USE_LOCAL_SECRETS: false
PREFECT__CONTEXT__FLOW_RUN_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PREFECT__CONTEXT__FLOW_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PREFECT__CONTEXT__IMAGE: prefecthq/prefect:latest
PREFECT__LOGGING__LOG_TO_CLOUD: true
PREFECT__ENGINE__FLOW_RUNNER__DEFAULT_CLASS: prefect.engine.cloud.CloudFlowRunner
PREFECT__ENGINE__TASK_RUNNER__DEFAULT_CLASS: prefect.engine.cloud.CloudTaskRunner
Mounts:
/etc/secret-volume from secret-volume (ro)
Volumes:
secret-volume:
Type: Secret (a volume populated by a Secret)
SecretName: prefect-agent
Optional: false
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 3s job-controller Created pod: prefect-job-xxxxxxxx-j5tgc
`kubectl describe pod prefect-job-xxxxxxxx-j5tgc`:
Name: prefect-job-xxxxxxxx-j5tgc
Namespace: prefect-deploy-keys
Priority: 0
Node: docker-desktop/000.000.00.0
Start Time: Wed, 12 May 2021 16:03:17 -0600
Labels: <http://app.kubernetes.io/instance=prefect-agent|app.kubernetes.io/instance=prefect-agent>
<http://app.kubernetes.io/managed-by=Helm|app.kubernetes.io/managed-by=Helm>
<http://app.kubernetes.io/name=prefect-agent|app.kubernetes.io/name=prefect-agent>
<http://app.kubernetes.io/version=0.14.17-python3.8|app.kubernetes.io/version=0.14.17-python3.8>
controller-uid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<http://helm.sh/chart=prefect-agent-0.1.0-dev|helm.sh/chart=prefect-agent-0.1.0-dev>
job-name=prefect-job-xxxxxxxx
<http://prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx|prefect.io/flow_run_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
<http://prefect.io/identifier=xxxxxxxx|prefect.io/identifier=xxxxxxxx>
Annotations: <none>
Status: Succeeded
IP: 00.0.0.00
IPs:
IP: 00.0.0.00
Controlled By: Job/prefect-job-xxxxxxxx
Containers:
flow:
Container ID: <docker://26adbbea01570fcac0015dc04c11de355f0cc3bd77c01bae969047127b631c6>2
Image: prefecthq/prefect:latest
Image ID: <docker-pullable://prefecthq/prefect@sha256:79a59032175275a19ede749ce1512b2fafc59a6e6b105d38ef074a0ce6c4332f>
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
Args:
prefect
execute
flow-run
State: Terminated
Reason: Completed
Exit Code: 0
Started: Wed, 12 May 2021 16:03:20 -0600
Finished: Wed, 12 May 2021 16:03:20 -0600
Ready: False
Restart Count: 0
Environment:
PREFECT__LOGGING__LEVEL: INFO
PREFECT__BACKEND: cloud
PREFECT__CLOUD__AGENT__LABELS: ['my-label']
PREFECT__CLOUD__API: <https://api.prefect.io>
PREFECT__CLOUD__AUTH_TOKEN: ****
PREFECT__CLOUD__USE_LOCAL_SECRETS: false
PREFECT__CONTEXT__FLOW_RUN_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PREFECT__CONTEXT__FLOW_ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PREFECT__CONTEXT__IMAGE: prefecthq/prefect:latest
PREFECT__LOGGING__LOG_TO_CLOUD: true
PREFECT__ENGINE__FLOW_RUNNER__DEFAULT_CLASS: prefect.engine.cloud.CloudFlowRunner
PREFECT__ENGINE__TASK_RUNNER__DEFAULT_CLASS: prefect.engine.cloud.CloudTaskRunner
Mounts:
/etc/secret-volume from secret-volume (ro)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-xxxxx (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
secret-volume:
Type: Secret (a volume populated by a Secret)
SecretName: prefect-agent
Optional: false
default-token-nj6rp:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-xxxxx
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <http://node.kubernetes.io/not-ready:NoExecute|node.kubernetes.io/not-ready:NoExecute> op=Exists for 300s
<http://node.kubernetes.io/unreachable:NoExecute|node.kubernetes.io/unreachable:NoExecute> op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 5s default-scheduler Successfully assigned prefect-deploy-keys/prefect-job-xxxxxxxx-j5tgc to docker-desktop
Normal Pulled 2s kubelet Container image "prefecthq/prefect:latest" already present on machine
Normal Created 2s kubelet Created container flow
Normal Started 2s kubelet Started container flow
`kubectl get logs -p prefect-job-xxxxxxxx-j5tgc`:
Getting you a shell in flow...
Usage: prefect [OPTIONS] COMMAND [ARGS]...
The Prefect CLI for creating, managing, and inspecting your flows.
Note: a Prefect Cloud API token is required for all Cloud related commands. If a token
is not set then run `prefect auth login` to set it.
Query Commands:
get List high-level object information
describe Retrieve detailed object descriptions
Action Commands:
agent Manage agents
create Create objects
delete Delete objects
execute Execute a flow's environment
run Run a flow
register Register flows with an API
heartbeat Send heartbeats for a run
Setup Commands:
auth Handle Prefect Cloud authorization
backend Switch between `server` and `cloud` backends
server Interact with the Prefect Server
Miscellaneous Commands:
version Print the current Prefect version
config Output Prefect config
diagnostics Output Prefect diagnostic information
Options:
-h, --help Show this message and exit.
Commands:
agent Manage Prefect agents.
build Build one or more flows.
register Register one or more flows into a project.
Kevin Kho
Zach Hodowanec
05/12/2021, 10:51 PMZach Hodowanec
05/12/2021, 10:53 PMTyler Wanner
05/13/2021, 3:33 AMcommand: ["/bin/sh", "-c"]
from my job specTyler Wanner
05/13/2021, 4:17 AMZach Hodowanec
05/13/2021, 3:05 PMcommand: ["/bin/sh", "-c"]
from my job spec does appear to resolve the issue. Thanks!Zach Hodowanec
05/13/2021, 3:05 PMFailed to load and execute Flow's environment: FileNotFoundError(2, "No such file or directory: 'ssh'")
I have tried mounting in my private keys to the following locations but don't seem to be having any luck.
• /etc/ssh/secret-volume
• /ssh/secret-volume
• /ssh
Do you know what the correct location to mount the key into is?Kevin Kho
Zach Hodowanec
05/13/2021, 3:09 PMuse_ssh=true
flag in the Git Storage definition.Kevin Kho
Zach Angell
dulwich
https://www.dulwich.io/, and I'm having trouble following how they configure it.
FWIW on my local machine, dulwich
correctly checks /Users/zangell/.ssh/id_rsa
Any chance permissions on the /ssh
directory are restricted in your case?Zach Hodowanec
05/13/2021, 5:24 PM/ssh
directory in the pod but it matches my local machine config so I'm not sure if that's the problemZach Angell
Zach Hodowanec
05/13/2021, 6:05 PMZach Angell
# ... flow set up, etc
storage = Git(..., use_ssh=True)
storage.add_flow(flow) # the Flow object
storage.get_flow(flow.name) # try to load the flow from git storage
Zach Hodowanec
05/13/2021, 7:21 PMEnumerating objects: 34, done.
Counting objects: 100% (34/34), done.
Compressing objects: 100% (24/24), done.
Total 34 (delta 9), reused 28 (delta 6), pack-reused 0
Checking out xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Zach Hodowanec
05/13/2021, 7:29 PM/tmp
directory referenced, but if I try to mount the SSH keys in that directory the final line of the stack trace references a /var/tmp
directory instead.
[Errno 2] No such file or directory: 'ssh': 'ssh'
Traceback (most recent call last):
File "/usr/local/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/prefect/cli/execute.py", line 90, in flow_run
raise exc
File "/usr/local/lib/python3.7/site-packages/prefect/cli/execute.py", line 67, in flow_run
flow = storage.get_flow(flow_data.name)
File "/usr/local/lib/python3.7/site-packages/prefect/storage/git.py", line 122, in get_flow
clone_depth=self.clone_depth,
File "/usr/local/lib/python3.7/site-packages/prefect/utilities/git.py", line 48, in __enter__
source=self.git_clone_url, target=self.temp_dir.name, depth=self.clone_depth
File "/usr/local/lib/python3.7/site-packages/dulwich/porcelain.py", line 476, in clone
**kwargs
File "/usr/local/lib/python3.7/site-packages/dulwich/porcelain.py", line 1559, in fetch
fetch_result = client.fetch(path, r, progress=errstream.write, depth=depth)
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 528, in fetch
depth=depth,
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1009, in fetch_pack
proto, can_read, stderr = self._connect(b"upload-pack", path)
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1659, in _connect
self.host, argv, port=self.port, username=self.username, **kwargs
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1522, in run_command
stderr=subprocess.PIPE,
File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ssh': 'ssh'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/weakref.py", line 648, in _exitfunc
f()
File "/usr/local/lib/python3.7/weakref.py", line 572, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/usr/local/lib/python3.7/tempfile.py", line 797, in _cleanup
_shutil.rmtree(name)
File "/usr/local/lib/python3.7/shutil.py", line 485, in rmtree
onerror(os.lstat, path, sys.exc_info())
File "/usr/local/lib/python3.7/shutil.py", line 483, in rmtree
orig_st = os.lstat(path)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpc427y2_n'
Zach Angell
Zach Angell
Zach Hodowanec
05/14/2021, 1:42 AMprefecthq/prefect:latest
Docker container.
1. Create Flow
import os
from prefect import Flow, Parameter, task
from prefect.run_configs import KubernetesRun
from prefect.storage import Git
@task(log_stdout=True)
def say_hello(name):
print("Hello, {}!".format(name))
with Flow("Hello World") as flow:
thename = Parameter("name")
say_hello(thename)
storage = Git(
repo="my/repo",
flow_path="src/flows/hello_world.py",
branch_name="my/branch-name",
use_ssh=True,
)
storage.add_flow(flow) # the Flow object
storage.get_flow(flow.name) # try to load the flow from git storage
2. Publish Flow to GitHub
3. Run Docker Image
$ docker run --rm -it --entrypoint sh -v path/to/flow:/src -v ~/.ssh:/root/.ssh prefecthq/prefect:latest
4. Debug Flow
# python /src/my_test_file.py
Traceback (most recent call last):
File "/src/TestCloningRepoWithSSH.py", line 26, in <module>
storage.get_flow(flow.name) # try to load the flow from git storage
File "/usr/local/lib/python3.7/site-packages/prefect/storage/git.py", line 122, in get_flow
clone_depth=self.clone_depth,
File "/usr/local/lib/python3.7/site-packages/prefect/utilities/git.py", line 48, in __enter__
source=self.git_clone_url, target=self.temp_dir.name, depth=self.clone_depth
File "/usr/local/lib/python3.7/site-packages/dulwich/porcelain.py", line 476, in clone
**kwargs
File "/usr/local/lib/python3.7/site-packages/dulwich/porcelain.py", line 1559, in fetch
fetch_result = client.fetch(path, r, progress=errstream.write, depth=depth)
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 528, in fetch
depth=depth,
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1009, in fetch_pack
proto, can_read, stderr = self._connect(b"upload-pack", path)
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1659, in _connect
self.host, argv, port=self.port, username=self.username, **kwargs
File "/usr/local/lib/python3.7/site-packages/dulwich/client.py", line 1522, in run_command
stderr=subprocess.PIPE,
File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ssh': 'ssh'
Traceback (most recent call last):
File "/usr/local/lib/python3.7/weakref.py", line 648, in _exitfunc
f()
File "/usr/local/lib/python3.7/weakref.py", line 572, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "/usr/local/lib/python3.7/tempfile.py", line 797, in _cleanup
_shutil.rmtree(name)
File "/usr/local/lib/python3.7/shutil.py", line 485, in rmtree
onerror(os.lstat, path, sys.exc_info())
File "/usr/local/lib/python3.7/shutil.py", line 483, in rmtree
orig_st = os.lstat(path)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp9goeajxv'
Zach Hodowanec
05/14/2021, 1:44 AMid_rsa
, id_rsa.pub
, and known_hosts
files from my local machine into the following locations in the Docker container...
• /.ssh
• /ssh
• /etc/.ssh
• /etc/ssh
• /root/.ssh
• /root/ssh
• /home/user/.ssh
• /home/user/ssh
...none seem to work so farZach Angell
Zach Hodowanec
05/14/2021, 2:06 PMZach Hodowanec
05/14/2021, 2:07 PMZach Angell
/root/.ssh
is correct.Zach Angell
Git
storage class and I'm not familiar with configuring ssh keys for Docker. I assumed it was straightforward. I'll do some testing today to see if I can get it working. If I can't, I'll file a bug.Zach Angell
prefecthq/prefect:latest
, actually I don't think it will work. We don't every apt-get install ssh-client
, which would explain the ssh
not found error.Zach Angell
Zach Hodowanec
05/17/2021, 4:12 PMKevin Kho
Zach Hodowanec
05/28/2021, 6:12 PMZach Angell
prefecthq/prefect
as a base image. None of the documentation or process is Prefect specific, just generic instructions on setting up ssh + DockerZach Hodowanec
05/28/2021, 6:51 PMZach Angell
Zach Angell
Dockerfile
FROM prefecthq/prefect:latest
RUN apt update && apt install -y openssh-client
Next, we'll need to use that image in our run config, here's my whole flow including my run config
from prefect import Flow, Parameter, task
from prefect.run_configs import KubernetesRun
from prefect.storage import Git
@task(log_stdout=True)
def say_hello(name):
print("Hello, {}!".format(name))
with Flow("Hello World") as flow:
thename = Parameter("name")
say_hello(thename)
storage = Git(
repo="zangell44/single-prefect-flow",
flow_path="flow2.py",
use_ssh=True,
)
flow.run_config = KubernetesRun(image=<my-image>)
flow.storage = storage
flow.register("test")
Finally, we'll need to do some configuration in kubernetes to make the ssh key and known_hosts files available.
Step 1: Create a Kubernetes secret with the ssh key (id_ed25519
for me) and known hosts file.
kubectl create secret generic my-ssh-key --from-file=id_ed25519=/path/to/id_ed25519 --from-file=known_hosts=/path/to/known_hosts
Step 2: Create a custom job template to mount the secret to /root/.ssh
. Here's my custom job template yaml
apiVersion: batch/v1
kind: Job
spec:
template:
spec:
containers:
- name: flow
volumeMounts:
- name: ssh-key
readOnly: true
mountPath: "/root/.ssh"
volumes:
- name: ssh-key
secret:
secretName: my-ssh-key
optional: false
defaultMode: 0600
Step 3: Finally, we'll need to configure our agent to use the custom job template on startup. (This can also be done via run config)
prefect agent kubernetes start --job-template /path/to/job_template.yaml
We would also recommend configuring a service account to permission the secret properly. You can provide the service account name either on agent start or on the run config https://docs.prefect.io/orchestration/agents/kubernetes.html#service-account
There's definitely a few improvements we'd like to make to simplify this process going forward and we're happy to hear feedback!Zach Hodowanec
06/15/2021, 7:37 PMgit
instead of openssh-client
. Unfortunately neither solution actually works as I continue to receive the following error:
Failed to load and execute Flow's environment: HangupException('Host key verification failed.\r')
Do you have any additional ideas for making Deploy Keys useable in the Prefect Docker Image?Zach Angell
known_hosts
file is not configured correctly. I ran into that error if the known_hosts
file was missing entirelyZach Angell
/root/.ssh/known_hosts
exists and includes the host you're trying to clone from (e.g. github.com)Zach Hodowanec
06/15/2021, 8:29 PM/root/.ssh/known_hosts
isn't really possible given how quickly the job fails and Kubernetes spinning up a new Pod to resolve the issue. Any suggestions for achieving this?
I did mount the same keys into my Agent to verify the Helm deployment and everything checks out there. I would imagine that it's also mounted properly in the Job spec as it's using the same mechanism for mounting the keys.
I also verified that mounting the exact same keys to the exact same location of the exact same image results in a successful pull of my flow repository when just running the Docker image outside of Kubernetes.
Have you successfully used Deploy Keys + Kubernetes Agent?Zach Angell
Zach Hodowanec
06/15/2021, 8:56 PMZanie
Zach Hodowanec
06/16/2021, 9:10 PMZanie
Zach Hodowanec
06/16/2021, 10:12 PMPermission denied (publickey)
error I get when running a flow attempting to utilize Git storage. While I was in the Pod I decided to generate a new Deploy Key with the values stored at /root/.ssh/ssh-publickey
but continue to get the same error.