https://prefect.io logo
#best-practices
Title
# best-practices
b

Bernardo Galvao

05/09/2022, 11:46 AM
heyy, I am setting up prefect in an on-prem production environment and I'm looking into setting up Storage. I would like to know if there is any recommended KV store docker image that I should use for this purpose?
๐Ÿ‘‹ 1
a

Anna Geller

05/09/2022, 11:58 AM
The recommended docker image is any of the official Prefect base images here - for Orion, you would need those tagged with 2.0 beta e.g. 2.0b3-python3.9 Regarding KV storage, this is not yet released and documented, so you may need to wait a bit. In the meantime, I'd highly recommend S3 (or similar cloud object storage)
๐Ÿ‘ 1
it may be a bit opinionated, but I actually like object storage for flow code more than KV Store - from AWS S3 FAQ: Q: How reliable is Amazon S3? Amazon S3 gives any developer access to the same highly scalable, highly available, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The S3 Standard storage class is designed for 99.99% availability. All of these storage classes are backed by the Amazon S3 Service Level Agreement.
b

Bernardo Galvao

05/09/2022, 12:08 PM
I agree with you, but in my case, the client wants the system to be in a closed private network, which excludes any cloud solution unfortunately. ๐Ÿ˜ž I would definitely prefer that solution ๐Ÿ˜„
๐Ÿ‘ 1
a

Anna Geller

05/09/2022, 12:11 PM
b

Bernardo Galvao

05/09/2022, 12:12 PM
That's nice! I'll loot into it ๐Ÿ‘€
๐Ÿ‘ 1
a

Anna Geller

05/09/2022, 12:12 PM
otherwise local storage
b

Bernardo Galvao

05/09/2022, 12:15 PM
Now that you mention it, I played around with
prefect storage create
and did try Local Storage. I was hoping to see the directory being created in the filesystem, but I didn't see it happen
d

davzucky

05/09/2022, 12:16 PM
Did you look at solution like minio or ceph? This allow you to have S3 compatible storage on prem You can look at well at Enterprise grade with dell ECS for example. https://www.dell.com/en-hk/dt/storage/ecs/index.htm#scroll=off We are using a mix of minio and ECS with success with prefect
๐Ÿ‘€ 1
๐Ÿ‘ 1
a

Anna Geller

05/09/2022, 12:17 PM
you should be able to set the desired path and then when you create a deployment, Prefect will store the flow code there
๐Ÿ‘ 1
d

davzucky

05/09/2022, 12:18 PM
The solution I told you should work out of the box with fsspec.
๐Ÿ‘ 2
b

Bernardo Galvao

05/27/2022, 4:23 PM
Hi @davzucky, I am struggling with the final step of configuring Minio storage of Prefect, perhaps you could help me out? โ€ข I've spun up a Prefect and a Minio instance in Docker Swarm. โ€ข I've
ping minio
from the Prefect container alright. โœ… โ€ข There are 6 options to pass when creating an S3 storage for Prefect โ€ข I dont know yet how to validate the
BUCKET
option because it accepts any value! So I cannot be sure whether it is working as of yet. I've created a user "prefect" and a bucket "prefect" from Minio's console. Now I need to know how to pass the
BUCKET
value correctly. I find it odd that I cannot point out the S3 endpoint url pointing to my Minio instance before passing the bucket name.
Copy code
Select a storage type to create: 5
You've selected S3 Storage. It has 6 option(s). 
BUCKET: <http://minio/prefect>
REGION NAME (optional): 
PROFILE NAME (optional): 
AWS ACCESS KEY ID (optional): prefect
AWS SESSION TOKEN (optional): 
AWS SECRET ACCESS KEY (optional): prefecty
Choose a name for this storage configuration: minio
Validating configuration...
Registering storage with server...
Registered storage 'minio' with identifier '232d4851-0373-4ecb-b295-18465e88382f'.
root@9bb445098cef:/opt/prefect# prefect storage ls
                                           Configured Storage                                            
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ                                      โ”ƒ              โ”ƒ Storage        โ”ƒ              โ”ƒ                 โ”ƒ
โ”ƒ                                   ID โ”ƒ Storage Type โ”ƒ Version        โ”ƒ Name         โ”ƒ Server Default  โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ 232d4851-0373-4ecb-b295-18465e88382f โ”‚ S3 Storage   โ”‚ 1.0            โ”‚ minio        โ”‚                 โ”‚
โ”‚ 5a6f982f-1b9d-452f-bbc4-9e5a5dc724af โ”‚ S3 Storage   โ”‚ 1.0            โ”‚ prefectminio โ”‚ ๐Ÿฆ†              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
d

davzucky

05/30/2022, 12:32 AM
Let me have a try this week, as I haven't done it yet with Prefect 2.0. Will come back to you about that.
b

Bernardo Galvao

05/30/2022, 8:46 AM
thanks ๐Ÿ™‚
a

Anna Geller

05/30/2022, 9:38 AM
Thanks so much, davzucky for helping here. Bernanrdo, it could be a Docker network issue - make sure you can access it from where Prefect is running - is on-prem the reason why you can't use S3?
b

Bernardo Galvao

06/01/2022, 3:44 PM
is on-prem the reason why you can't use S3?
Yes indeed. The servers sit inside a closed network, so I am resorting to Minio.
a

Anna Geller

06/01/2022, 8:25 PM
thanks for explaining. Not sure whether you saw the announcement here but we'll release changes to the storage abstraction this Thursday - could you check then whether the issue is resolved?
b

Bernardo Galvao

06/02/2022, 9:15 AM
Yes, I will check as soon as the image is released ๐Ÿ™‚
๐Ÿ™Œ 1
@Anna Geller what is the easiest way to make Prefect write to an S3 bucket? Is running a flow enough? Or do I have to
prefect deployment create
?
a

Anna Geller

06/03/2022, 9:40 AM
yes exactly, you would need to create a deployment and this way, Prefect will upload your flow to the specified S3 storage
๐Ÿ‘ 1
b

Bernardo Galvao

06/06/2022, 10:08 AM
@Anna Geller Made it work with Minio finally ๐ŸŽ‰ It was a gamble but it worked ๐Ÿ˜… At least within Docker swarm - but probably for any AWS S3 alternative - the solution was to specify
"endpoint_url"
@davzucky here is a solution ๐Ÿ™‚ References: โ€ข https://s3fs.readthedocs.io/en/latest/#s3-compatible-storage โ€ข https://stackoverflow.com/a/71180307/13187430
Copy code
# for boto
os.environ["AWS_ACCESS_KEY_ID"] = "minio"
os.environ["AWS_SECRET_ACCESS_KEY"] = "miniominio"

minio_storage = FileStorageBlock(
    base_path='<s3://prefect/deployments>',
    key_type='hash',
    options={  # Additional options to pass to the underlying fsspec file system.
        # a gamble that as Prefect is using s3fs (that in its turn also uses fsspec)
        # these options are consumed by fsspec
        "client_kwargs": {"endpoint_url": "<http://minio:9000>"}
    }
)
๐Ÿ‘ 2
It doesn't seem possible at the moment to create and set this storage option as default using the prefect CLI - as it doesn't ask for any optional "endpoint_url". But I'll take it.
๐Ÿ™Œ 1
a

Anna Geller

06/06/2022, 10:43 AM
great work, thanks so much for sharing!
๐Ÿ˜Š 1
also shared here for posterity
๐Ÿ‘€ 1
75 Views