Skip to content

Commit

Permalink
docs: fix Jina on Kubernetes/docker-compose section (#4176)
Browse files Browse the repository at this point in the history
* docs: fix Jina on Kubernetes section

* docs: fix docker-compose docs
  • Loading branch information
alaeddine-13 committed Jan 18, 2022
1 parent cf99fd8 commit f6e2103
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
18 changes: 8 additions & 10 deletions docs/advanced/experimental/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,24 @@ docker-compose up -f docker-compose.yml
Once we see that all the Services in the Flow are ready, we can start sending index and search requests.

```python
import os

from jina.clients import Client
from jina import DocumentArray

client = Client(host='localhost', port=8080)
client.show_progress = True
indexing_documents = DocumentArray.from_files('./imgs/*.jpg')
indexed_documents = []
for resp in client.post(
indexing_documents = DocumentArray.from_files('./imgs/*.jpg').apply(lambda d: d.load_uri_to_image_blob())

docs = client.post(
'/index', inputs=indexing_documents, return_results=True
):
indexed_documents.extend(resp.docs)
)

print(f'Indexed documents: {len(docs)}')

print(f' Indexed documents: {[doc.uri for doc in indexed_documents]}')
query_doc = indexing_documents[0]
query_responses = client.post(
'/search', inputs=query_doc, return_results=True
)

closest_match_uri = query_responses[0].docs[0].matches[0].uri
print('closest_match_uri: ', closest_match_uri)
matches = query_responses[0].data.docs[0].matches
print(f'Matched documents: {len(matches)}')
```
51 changes: 36 additions & 15 deletions docs/advanced/experimental/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,59 @@ You should expect the following file structure generated:

As you can see, the Flow contains configuration for the gateway and the rest of executors

Let's create a kubernetes namespace for our Flow:

```shell
kubectl create namespace custom-namespace
```

Now, you can deploy this Flow to you cluster in the following way:
```shell
kubectl apply -f ./k8s_flow
kubectl apply -R -f ./k8s_flow
```

We can check that the pods were created:
```shell
kubectl get pods -n custom-namespace
```

```text
NAME READY STATUS RESTARTS AGE
encoder-8b5575cb9-bh2x8 1/1 Running 0 60m
encoder-8b5575cb9-gx78g 1/1 Running 0 60m
encoder-head-0-55bbb477ff-p2bmk 1/1 Running 0 60m
gateway-7df8765bd9-xf5tf 1/1 Running 0 60m
indexer-0-8f676fc9d-4fh52 1/1 Running 0 60m
indexer-1-55b6cc9dd8-gtpf6 1/1 Running 0 60m
indexer-head-0-6fcc679d95-8mrm6 1/1 Running 0 60m
```

Note that the Jina gateway was deployed with name `gateway-7df8765bd9-xf5tf`.

Once we see that all the Deployments in the Flow are ready, we can start indexing documents.

```python
import os
import portforward

from jina.clients import Client
from jina import DocumentArray

config_path = os.environ['KUBECONFIG']

with portforward.forward(
'custom-namespace', 'gateway', 8080, 8080, config_path
'custom-namespace', 'gateway-7df8765bd9-xf5tf', 8080, 8080
):
client = Client(host='localhost', port=8080)
client.show_progress = True
indexed_documents = []
for resp in client.post(
'/index', inputs=DocumentArray.from_files('./imgs/*.jpg'), return_results=True
):
indexed_documents.extend(resp.docs)
docs = client.post(
'/index', inputs=DocumentArray.from_files('./imgs/*.jpg').apply(lambda d: d.load_uri_to_image_blob()),
return_results=True
)

print(f' Indexed documents: {[doc.uri for doc in indexed_documents]}')
print(f' Indexed documents: {len(docs)}')
```

```{admonition} Caution
:class: caution
We heavily recommend you to deploy each `Flow` into a separate namespace. In particular it should not be deployed into namespaces, where other essential non Jina services are running.
We heavily recommend you to deploy each `Flow` into a separate namespace. In particular, it should not be deployed into namespaces, where other essential non Jina services are running.
If `custom-namespace` has been used by another `Flow`, please set a different `k8s_namespace` name.
```

Expand Down Expand Up @@ -148,10 +168,11 @@ import os
host = os.environ['EXTERNAL_IP']
port = 80
url = f'http://{host}:{port}'
doc = DocumentArray.from_files('./imgs/*.jpg')[0].dict()

doc = DocumentArray.from_files('./imgs/*.jpg').apply(lambda d: d.load_uri_to_image_blob())[0].to_dict()
resp = requests.post(f'{url}/search', json={'data': [doc]})
closest_match_uri = resp.json()['data']['docs'][0]['matches'][0]['uri']
print('closest_match_uri: ', closest_match_uri)
matches = resp.json()['data']['docs'][0]['matches']
print(f'Matched documents: {len(matches)}')
```

## Scaling Executors on Kubernetes
Expand Down

0 comments on commit f6e2103

Please sign in to comment.