Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated python-helm-demo example to use MinIO instead of GS #4691

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 120 additions & 39 deletions examples/python-helm-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,168 @@

For this tutorial, we set up Feast with Redis.

We use the Feast CLI to register and materialize features, and then retrieving via a Feast Python feature server deployed in Kubernetes
We use the Feast CLI to register and materialize features from the current machine, and then retrieving via a
Feast Python feature server deployed in Kubernetes

## First, let's set up a Redis cluster
1. Start minikube (`minikube start`)
2. Use helm to install a default Redis cluster
1. Use helm to install a default Redis cluster

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these numbers all 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdown replaces them with the actual sequence:
https://www.markdownguide.org/basic-syntax/#ordered-lists

```bash
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install my-redis bitnami/redis
```
![](redis-screenshot.png)
3. Port forward Redis so we can materialize features to it
1. Port forward Redis so we can materialize features to it

```bash
kubectl port-forward --namespace default svc/my-redis-master 6379:6379
```
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.
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.

```bash
export REDIS_PASSWORD=$(kubectl get secret --namespace default my-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
echo $REDIS_PASSWORD
```

## Then, let's set up a MinIO S3 store
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).

1. Deploy MinIO instance:
```
kubectl apply -f minio-dev.yaml
```

1. Forward the UI port:
```console
kubectl port-forward svc/minio-service 9090:9090
```
1. Login to (localhost:9090)[http://localhost:9090] as `minio`/`minio123` and create bucket called `feast-demo`.
1. Stop previous port forwarding and forward the API port instead:
```console
kubectl port-forward svc/minio-service 9000:9000
```

## Next, we setup a local Feast repo
1. Install Feast with Redis dependencies `pip install "feast[redis]"`
2. Make a bucket in GCS (or S3)
3. The feature repo is already setup here, so you just need to swap in your GCS bucket and Redis credentials.
We need to modify the `feature_store.yaml`, which has two fields for you to replace:
1. Install Feast with Redis dependencies `pip install "feast[redis,aws]"`
1. The feature repo is already setup here, so you just need to swap in your Redis credentials.
We need to modify the `feature_store.yaml`, which has one field for you to replace:
```console
sed "s/_REDIS_PASSWORD_/${REDIS_PASSWORD}/" feature_repo/feature_store.yaml.template > feature_repo/feature_store.yaml
cat feature_repo/feature_store.yaml
```

Example repo:
```yaml
registry: gs://[YOUR GCS BUCKET]/demo-repo/registry.db
registry: s3://localhost:9000/feast-demo/registry.db
project: feast_python_demo
provider: gcp
provider: local
online_store:
type: redis
# Note: this would normally be using instance URL's to access Redis
connection_string: localhost:6379,password=[YOUR PASSWORD]
connection_string: localhost:6379,password=****
offline_store:
type: file
entity_key_serialization_version: 2
```
4. Run `feast apply` from within the `feature_repo` directory to apply your local features to the remote registry
- Note: you may need to authenticate to gcloud first with `gcloud auth login`
5. Materialize features to the online store:
1. To run `feast apply` from the current machine we need to define the AWS credentials to connect the MinIO S3 store, which
are defined in [minio.env](./minio.env):
```console
source minio.env
cd feature_repo
feast apply
```
1. Let's validate the setup by running some queries
```console
feast entities list
feast feature-views list
```
1. Materialize features to the online store:
```bash
cd feature_repo
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S")
feast materialize-incremental $CURRENT_TIME
```

## Now let's setup the Feast Server
1. Add the gcp-auth addon to mount GCP credentials:
```bash
minikube addons enable gcp-auth
```
2. Add Feast's Python/Go feature server chart repo
1. Add Feast's Python feature server chart repo
```bash
helm repo add feast-charts https://feast-helm-charts.storage.googleapis.com
helm repo update
```
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
```bash
sed -i '' 's/localhost:6379/my-redis-master:6379/g' feature_store.yaml
```
4. Install the Feast helm chart: `helm install feast-release feast-charts/feast-feature-server --set feature_store_yaml_base64=$(base64 feature_store.yaml)`
> **Dev instructions**: if you're changing the java logic or chart, you can do
1. `eval $(minikube docker-env)`
2. `make build-feature-server-dev`
3. `helm install feast-release ../../../infra/charts/feast-feature-server --set image.tag=dev --set feature_store_yaml_base64=$(base64 feature_store.yaml)`
5. (Optional): check logs of the server to make sure it’s working
1. For this tutorial, we'll use a predefined configuration where we just needs to inject the Redis service password:
```console
sed "s/_REDIS_PASSWORD_/$REDIS_PASSWORD/" online_feature_store.yaml.template > online_feature_store.yaml
cat online_feature_store.yaml
```
As you see, the connection points to `my-redis-master:6379` instead of `localhost:6379`.

1. Install the Feast helm chart:
```console
helm upgrade --install feast-online feast-charts/feast-feature-server \
--set fullnameOverride=online-server --set feast_mode=online \
--set feature_store_yaml_base64=$(base64 -i 'online_feature_store.yaml')
```
1. Patch the deployment to include MinIO settings:
```console
kubectl patch deployment online-server --type='json' -p='[
{
"op": "add",
"path": "/spec/template/spec/containers/0/env/-",
"value": {
"name": "AWS_ACCESS_KEY_ID",
"value": "minio"
}
},
{
"op": "add",
"path": "/spec/template/spec/containers/0/env/-",
"value": {
"name": "AWS_SECRET_ACCESS_KEY",
"value": "minio123"
}
},
{
"op": "add",
"path": "/spec/template/spec/containers/0/env/-",
"value": {
"name": "AWS_DEFAULT_REGION",
"value": "default"
}
},
{
"op": "add",
"path": "/spec/template/spec/containers/0/env/-",
"value": {
"name": "FEAST_S3_ENDPOINT_URL",
"value": "http://minio-service:9000"
}
}
]'
kubectl wait --for=condition=available deployment/online-server --timeout=2m
```
1. (Optional): check logs of the server to make sure it’s working
```bash
kubectl logs svc/feast-release-feast-feature-server
kubectl logs svc/online-server
```
6. Port forward to expose the grpc endpoint:
1. Port forward to expose the grpc endpoint:
```bash
kubectl port-forward svc/feast-release-feast-feature-server 6566:80
kubectl port-forward svc/online-server 6566:80
```
7. Run test fetches for online features:8.
- First: change back the Redis connection string to allow localhost connections to Redis
1. Run test fetches for online features:8.
```bash
sed -i '' 's/my-redis-master:6379/localhost:6379/g' feature_store.yaml
source minio.env
cd test
python test_python_fetch.py
```
- Then run the included fetch script, which fetches both via the HTTP endpoint and for comparison, via the Python SDK
```bash
python test_python_fetch.py

Output example:
```console
--- Online features with SDK ---
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.
conv_rate : [0.6799587607383728, 0.9761165976524353]
driver_id : [1001, 1002]

--- Online features with HTTP endpoint ---
conv_rate : [0.67995876 0.9761166 ]
driver_id : [1001 1002]
```
Binary file not shown.
10 changes: 0 additions & 10 deletions examples/python-helm-demo/feature_repo/feature_store.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
registry: s3://feast-demo/registry.db
project: feast_python_demo
provider: local
online_store:
type: redis
connection_string: localhost:6379,password=_REDIS_PASSWORD_
offline_store:
type: file
entity_key_serialization_version: 2
128 changes: 128 additions & 0 deletions examples/python-helm-demo/minio-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: minio-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
volumeMode: Filesystem
---
kind: Secret
apiVersion: v1
metadata:
name: minio-secret
stringData:
# change the username and password to your own values.
# ensure that the user is at least 3 characters long and the password at least 8
minio_root_user: minio
minio_root_password: minio123
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: minio
spec:
replicas: 1
selector:
matchLabels:
app: minio
template:
metadata:
labels:
app: minio
spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: minio-pvc
containers:
- resources:
limits:
cpu: 250m
memory: 1Gi
requests:
cpu: 20m
memory: 100Mi
readinessProbe:
tcpSocket:
port: 9000
initialDelaySeconds: 5
timeoutSeconds: 1
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
name: minio
livenessProbe:
tcpSocket:
port: 9000
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
env:
- name: MINIO_ROOT_USER
valueFrom:
secretKeyRef:
name: minio-secret
key: minio_root_user
- name: MINIO_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: minio-secret
key: minio_root_password
ports:
- containerPort: 9000
protocol: TCP
- containerPort: 9090
protocol: TCP
imagePullPolicy: IfNotPresent
volumeMounts:
- name: data
mountPath: /data
subPath: minio
terminationMessagePolicy: File
image: >-
quay.io/minio/minio:RELEASE.2023-06-19T19-52-50Z
args:
- server
- /data
- --console-address
- :9090
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: Recreate
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: minio-service
spec:
ipFamilies:
- IPv4
ports:
- name: api
protocol: TCP
port: 9000
targetPort: 9000
- name: ui
protocol: TCP
port: 9090
targetPort: 9090
internalTrafficPolicy: Cluster
type: ClusterIP
ipFamilyPolicy: SingleStack
sessionAffinity: None
selector:
app: minio
7 changes: 7 additions & 0 deletions examples/python-helm-demo/minio.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export AWS_ACCESS_KEY_ID=minio
export AWS_DEFAULT_REGION=default
#export AWS_S3_BUCKET=feast-demo
#export AWS_S3_ENDPOINT=http://localhost:9000
export FEAST_S3_ENDPOINT_URL=http://localhost:9000
export AWS_SECRET_ACCESS_KEY=minio123

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project: feast_python_demo
provider: local
registry: s3://feast-demo/registry.db
online_store:
type: redis
connection_string: my-redis-master:6379,password=_REDIS_PASSWORD_
entity_key_serialization_version: 2
7 changes: 7 additions & 0 deletions examples/python-helm-demo/test/feature_store.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
registry: s3://feast-demo/registry.db
project: feast_python_demo
provider: local
online_store:
path: http://localhost:6566
type: remote
entity_key_serialization_version: 2
Loading
Loading