|
3 | 3 |
|
4 | 4 | For this tutorial, we set up Feast with Redis.
|
5 | 5 |
|
6 |
| -We use the Feast CLI to register and materialize features, and then retrieving via a Feast Python feature server deployed in Kubernetes |
| 6 | +We use the Feast CLI to register and materialize features from the current machine, and then retrieving via a |
| 7 | +Feast Python feature server deployed in Kubernetes |
7 | 8 |
|
8 | 9 | ## First, let's set up a Redis cluster
|
9 | 10 | 1. Start minikube (`minikube start`)
|
10 |
| -2. Use helm to install a default Redis cluster |
| 11 | +1. Use helm to install a default Redis cluster |
11 | 12 | ```bash
|
12 | 13 | helm repo add bitnami https://charts.bitnami.com/bitnami
|
13 | 14 | helm repo update
|
14 | 15 | helm install my-redis bitnami/redis
|
15 | 16 | ```
|
16 | 17 | 
|
17 |
| -3. Port forward Redis so we can materialize features to it |
| 18 | +1. Port forward Redis so we can materialize features to it |
18 | 19 |
|
19 | 20 | ```bash
|
20 | 21 | kubectl port-forward --namespace default svc/my-redis-master 6379:6379
|
21 | 22 | ```
|
22 |
| -4. Get your Redis password using the command (pasted below for convenience). We'll need this to tell Feast how to communicate with the cluster. |
| 23 | +1. Get your Redis password using the command (pasted below for convenience). We'll need this to tell Feast how to communicate with the cluster. |
23 | 24 |
|
24 | 25 | ```bash
|
25 | 26 | export REDIS_PASSWORD=$(kubectl get secret --namespace default my-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
|
26 | 27 | echo $REDIS_PASSWORD
|
27 | 28 | ```
|
28 | 29 |
|
| 30 | +## Then, let's set up a MinIO S3 store |
| 31 | +Manifests have been taken from [Deploy Minio in your project](https://ai-on-openshift.io/tools-and-applications/minio/minio/#deploy-minio-in-your-project). |
| 32 | + |
| 33 | +1. Deploy MinIO instance: |
| 34 | + ``` |
| 35 | + kubectl apply -f minio-dev.yaml |
| 36 | + ``` |
| 37 | + |
| 38 | +1. Forward the UI port: |
| 39 | + ```console |
| 40 | + kubectl port-forward svc/minio-service 9090:9090 |
| 41 | + ``` |
| 42 | +1. Login to (localhost:9090)[http://localhost:9090] as `minio`/`minio123` and create bucket called `feast-demo`. |
| 43 | +1. Stop previous port forwarding and forward the API port instead: |
| 44 | + ```console |
| 45 | + kubectl port-forward svc/minio-service 9000:9000 |
| 46 | + ``` |
| 47 | + |
29 | 48 | ## Next, we setup a local Feast repo
|
30 |
| -1. Install Feast with Redis dependencies `pip install "feast[redis]"` |
31 |
| -2. Make a bucket in GCS (or S3) |
32 |
| -3. The feature repo is already setup here, so you just need to swap in your GCS bucket and Redis credentials. |
33 |
| - We need to modify the `feature_store.yaml`, which has two fields for you to replace: |
| 49 | +1. Install Feast with Redis dependencies `pip install "feast[redis,aws]"` |
| 50 | +1. The feature repo is already setup here, so you just need to swap in your Redis credentials. |
| 51 | + We need to modify the `feature_store.yaml`, which has one field for you to replace: |
| 52 | + ```console |
| 53 | + sed "s/_REDIS_PASSWORD_/${REDIS_PASSWORD}/" feature_repo/feature_store.yaml.template > feature_repo/feature_store.yaml |
| 54 | + cat feature_repo/feature_store.yaml |
| 55 | + ``` |
| 56 | + |
| 57 | + Example repo: |
34 | 58 | ```yaml
|
35 |
| - registry: gs://[YOUR GCS BUCKET]/demo-repo/registry.db |
| 59 | + registry: s3://localhost:9000/feast-demo/registry.db |
36 | 60 | project: feast_python_demo
|
37 |
| - provider: gcp |
| 61 | + provider: local |
38 | 62 | online_store:
|
39 | 63 | type: redis
|
40 |
| - # Note: this would normally be using instance URL's to access Redis |
41 |
| - connection_string: localhost:6379,password=[YOUR PASSWORD] |
| 64 | + connection_string: localhost:6379,password=**** |
42 | 65 | offline_store:
|
43 | 66 | type: file
|
44 | 67 | entity_key_serialization_version: 2
|
45 | 68 | ```
|
46 |
| -4. Run `feast apply` from within the `feature_repo` directory to apply your local features to the remote registry |
47 |
| - - Note: you may need to authenticate to gcloud first with `gcloud auth login` |
48 |
| -5. Materialize features to the online store: |
| 69 | +1. To run `feast apply` from the current machine we need to define the AWS credentials to connect the MinIO S3 store, which |
| 70 | +are defined in [minio.env](./minio.env): |
| 71 | + ```console |
| 72 | + source minio.env |
| 73 | + cd feature_repo |
| 74 | + feast apply |
| 75 | + ``` |
| 76 | +1. Let's validate the setup by running some queries |
| 77 | + ```console |
| 78 | + feast entities list |
| 79 | + feast feature-views list |
| 80 | + ``` |
| 81 | +1. Materialize features to the online store: |
49 | 82 | ```bash
|
| 83 | + cd feature_repo |
50 | 84 | CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S")
|
51 | 85 | feast materialize-incremental $CURRENT_TIME
|
52 | 86 | ```
|
53 | 87 |
|
54 | 88 | ## Now let's setup the Feast Server
|
55 |
| -1. Add the gcp-auth addon to mount GCP credentials: |
56 |
| - ```bash |
57 |
| - minikube addons enable gcp-auth |
58 |
| - ``` |
59 |
| -2. Add Feast's Python/Go feature server chart repo |
| 89 | +1. Add Feast's Python feature server chart repo |
60 | 90 | ```bash
|
61 | 91 | helm repo add feast-charts https://feast-helm-charts.storage.googleapis.com
|
62 | 92 | helm repo update
|
63 | 93 | ```
|
64 |
| -3. For this tutorial, because we don't have a direct hosted endpoint into Redis, we need to change `feature_store.yaml` to talk to the Kubernetes Redis service |
65 |
| - ```bash |
66 |
| - sed -i '' 's/localhost:6379/my-redis-master:6379/g' feature_store.yaml |
67 |
| - ``` |
68 |
| -4. Install the Feast helm chart: `helm install feast-release feast-charts/feast-feature-server --set feature_store_yaml_base64=$(base64 feature_store.yaml)` |
69 |
| - > **Dev instructions**: if you're changing the java logic or chart, you can do |
70 |
| - 1. `eval $(minikube docker-env)` |
71 |
| - 2. `make build-feature-server-dev` |
72 |
| - 3. `helm install feast-release ../../../infra/charts/feast-feature-server --set image.tag=dev --set feature_store_yaml_base64=$(base64 feature_store.yaml)` |
73 |
| -5. (Optional): check logs of the server to make sure it’s working |
| 94 | +1. For this tutorial, we'll use a predefined configuration where we just needs to inject the Redis service password: |
| 95 | + ```console |
| 96 | + sed "s/_REDIS_PASSWORD_/$REDIS_PASSWORD/" online_feature_store.yaml.template > online_feature_store.yaml |
| 97 | + cat online_feature_store.yaml |
| 98 | + ``` |
| 99 | + As you see, the connection points to `my-redis-master:6379` instead of `localhost:6379`. |
| 100 | + |
| 101 | +1. Install the Feast helm chart: |
| 102 | + ```console |
| 103 | + helm upgrade --install feast-online feast-charts/feast-feature-server \ |
| 104 | + --set fullnameOverride=online-server --set feast_mode=online \ |
| 105 | + --set feature_store_yaml_base64=$(base64 -i 'online_feature_store.yaml') |
| 106 | + ``` |
| 107 | +1. Patch the deployment to include MinIO settings: |
| 108 | + ```console |
| 109 | + kubectl patch deployment online-server --type='json' -p='[ |
| 110 | + { |
| 111 | + "op": "add", |
| 112 | + "path": "/spec/template/spec/containers/0/env/-", |
| 113 | + "value": { |
| 114 | + "name": "AWS_ACCESS_KEY_ID", |
| 115 | + "value": "minio" |
| 116 | + } |
| 117 | + }, |
| 118 | + { |
| 119 | + "op": "add", |
| 120 | + "path": "/spec/template/spec/containers/0/env/-", |
| 121 | + "value": { |
| 122 | + "name": "AWS_SECRET_ACCESS_KEY", |
| 123 | + "value": "minio123" |
| 124 | + } |
| 125 | + }, |
| 126 | + { |
| 127 | + "op": "add", |
| 128 | + "path": "/spec/template/spec/containers/0/env/-", |
| 129 | + "value": { |
| 130 | + "name": "AWS_DEFAULT_REGION", |
| 131 | + "value": "default" |
| 132 | + } |
| 133 | + }, |
| 134 | + { |
| 135 | + "op": "add", |
| 136 | + "path": "/spec/template/spec/containers/0/env/-", |
| 137 | + "value": { |
| 138 | + "name": "FEAST_S3_ENDPOINT_URL", |
| 139 | + "value": "http://minio-service:9000" |
| 140 | + } |
| 141 | + } |
| 142 | + ]' |
| 143 | + kubectl wait --for=condition=available deployment/online-server --timeout=2m |
| 144 | + ``` |
| 145 | +1. (Optional): check logs of the server to make sure it’s working |
74 | 146 | ```bash
|
75 |
| - kubectl logs svc/feast-release-feast-feature-server |
| 147 | + kubectl logs svc/online-server |
76 | 148 | ```
|
77 |
| -6. Port forward to expose the grpc endpoint: |
| 149 | +1. Port forward to expose the grpc endpoint: |
78 | 150 | ```bash
|
79 |
| - kubectl port-forward svc/feast-release-feast-feature-server 6566:80 |
| 151 | + kubectl port-forward svc/online-server 6566:80 |
80 | 152 | ```
|
81 |
| -7. Run test fetches for online features:8. |
82 |
| - - First: change back the Redis connection string to allow localhost connections to Redis |
| 153 | +1. Run test fetches for online features:8. |
83 | 154 | ```bash
|
84 |
| - sed -i '' 's/my-redis-master:6379/localhost:6379/g' feature_store.yaml |
| 155 | + source minio.env |
| 156 | + cd test |
| 157 | + python test_python_fetch.py |
85 | 158 | ```
|
86 |
| - - Then run the included fetch script, which fetches both via the HTTP endpoint and for comparison, via the Python SDK |
87 |
| - ```bash |
88 |
| - python test_python_fetch.py |
| 159 | + |
| 160 | + Output example: |
| 161 | + ```console |
| 162 | + --- Online features with SDK --- |
| 163 | + WARNING:root:_list_feature_views will make breaking changes. Please use _list_batch_feature_views instead. _list_feature_views will behave like _list_all_feature_views in the future. |
| 164 | + conv_rate : [0.6799587607383728, 0.9761165976524353] |
| 165 | + driver_id : [1001, 1002] |
| 166 | +
|
| 167 | + --- Online features with HTTP endpoint --- |
| 168 | + conv_rate : [0.67995876 0.9761166 ] |
| 169 | + driver_id : [1001 1002] |
89 | 170 | ```
|
0 commit comments