flat-byte-30366
08/26/2024, 6:40 AMancient-wolf-19325
08/26/2024, 6:40 AMflat-byte-30366
08/26/2024, 6:42 AMancient-wolf-19325
08/26/2024, 6:42 AMfrom flytekit import task, Resources
from flytekitplugins.pod import Pod, PodTemplate
from kubernetes.client import V1PodSpec, V1Container, V1VolumeMount, V1Volume, V1PersistentVolumeClaimVolumeSource
@task(
task_config=Pod(
pod_spec=V1PodSpec(
containers=[
V1Container(
name="primary",
image="your-container-image",
command=["/bin/sh", "-c", "s3fs your-bucket /mnt/s3 -o iam_role=your-iam-role"],
volume_mounts=[
V1VolumeMount(name="s3-bucket", mount_path="/mnt/s3")
],
security_context={"privileged": True}
)
],
volumes=[
V1Volume(
name="s3-bucket",
persistent_volume_claim=V1PersistentVolumeClaimVolumeSource(claim_name="your-pvc")
)
],
),
primary_container_name="primary",
),
requests=Resources(mem="1Gi"),
)
def my_s3fs_task() -> None:
# Your task logic here
pass
For using Kubernetes PVs and PVCs, you can create a PVC and mount it in your Flyte task as follows:
1. Create a PVC: Define a PVC in your Kubernetes cluster.
2. Mount the PVC in Flyte Task: Use the pod plugin or pod template to mount the PVC.
Example:
from flytekit import task, Resources
from flytekitplugins.pod import Pod
from kubernetes.client import V1PodSpec, V1Container, V1VolumeMount, V1Volume, V1PersistentVolumeClaimVolumeSource
@task(
task_config=Pod(
pod_spec=V1PodSpec(
containers=[
V1Container(
name="primary",
image="your-container-image",
volume_mounts=[
V1VolumeMount(name="persistent-storage", mount_path="/data")
],
)
],
volumes=[
V1Volume(
name="persistent-storage",
persistent_volume_claim=V1PersistentVolumeClaimVolumeSource(claim_name="your-pvc")
)
],
),
primary_container_name="primary",
),
requests=Resources(mem="1Gi"),
)
def my_pvc_task() -> None:
# Your task logic here
pass
Would you like more details on any specific part of this process?
Sources:
- Using PVs and PVCs 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.