• [+] expand all

Vespa quick start using Kubernetes

This guide describes how to install and run Vespa on a single machine using Kubernetes, K8s. See Getting Started for troubleshooting, next steps and other guides. Also see Vespa example on GKE.

Prerequisites:

  1. Validate environment, should be minimum 5G:

    Refer to Docker memory for details and troubleshooting:

    $ docker info | grep "Total Memory"
    
  2. Start Kubernetes cluster with minikube:
    $ minikube start --driver docker --memory 4096
    
  3. Clone the Vespa sample apps:
    $ git clone https://github.com/vespa-engine/sample-apps.git
    $ export VESPA_SAMPLE_APPS=`pwd`/sample-apps
    
  4. Create Kubernetes configuration files:
    $ cat << EOF > service.yml
    apiVersion: v1
    kind: Service
    metadata:
      name: vespa
      labels:
        app: vespa
    spec:
      selector:
        app: vespa
      type: NodePort
      ports:
      - name: container
        port: 8080
        targetPort: 8080
        protocol: TCP
      - name: config
        port: 19071
        targetPort: 19071
        protocol: TCP
    EOF
    
    $ cat << EOF > statefulset.yml
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: vespa
      labels:
        app: vespa
    spec:
      replicas: 1
      serviceName: vespa
      selector:
        matchLabels:
          app: vespa
      template:
        metadata:
          labels:
            app: vespa
        spec:
          containers:
          - name: vespa
            image: vespaengine/vespa
            imagePullPolicy: Always
            securityContext:
              privileged: true
            ports:
            - containerPort: 8080
              protocol: TCP
            readinessProbe:
              httpGet:
                path: /ApplicationStatus
                port: 19071
                scheme: HTTP
    EOF
    
  5. Start the service:
    $ kubectl apply -f service.yml -f statefulset.yml
    
  6. Wait for the service to enter a running state:
    $ kubectl get pods --watch
    
    Wait for STATUS Running:
        NAME      READY   STATUS              RESTARTS   AGE
        vespa-0   0/1     ContainerCreating   0          8s
        vespa-0   0/1     Running             0          2m4s
    
  7. Start port forwarding from localhost to pod:
    $ kubectl port-forward vespa-0 19071 8080 &
    
  8. Wait for configserver start - wait for 200 OK:
    $ curl -s --head http://localhost:19071/ApplicationStatus
    
  9. Zip the application package:
    $ (cd ${VESPA_SAMPLE_APPS}/album-recommendation/src/main/application && \
      zip -r ../../../../../application.zip .)
    
  10. Deploy and activate the application package:
    $ curl --header Content-Type:application/zip --data-binary @application.zip \
      localhost:19071/application/v2/tenant/default/prepareandactivate
    
  11. Ensure the application is active - wait for 200 OK:

    This normally takes a minute or so:

    $ curl -s --head http://localhost:8080/ApplicationStatus
    
  12. Feed documents:
    $ curl -s -H "Content-Type:application/json" \
      --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation/src/test/resources/A-Head-Full-of-Dreams.json \
      http://localhost:8080/document/v1/mynamespace/music/docid/a-head-full-of-dreams
    $ curl -s -H "Content-Type:application/json" \
      --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation/src/test/resources/Love-Is-Here-To-Stay.json \
      http://localhost:8080/document/v1/mynamespace/music/docid/love-is-here-to-stay
    $ curl -s -H "Content-Type:application/json" \
      --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation/src/test/resources/Hardwired...To-Self-Destruct.json \
      http://localhost:8080/document/v1/mynamespace/music/docid/hardwired-to-self-destruct
    
  13. Make a query:

    $ curl "http://localhost:8080/search/?ranking=rank_albums&yql=select%20%2A%20from%20sources%20%2A%20where%20sddocname%20contains%20%22music%22&input.query(user_profile)=%7B%7Bcat%3Apop%7D%3A0.8%2C%7Bcat%3Arock%7D%3A0.2%2C%7Bcat%3Ajazz%7D%3A0.1%7D"
    

    You can also view query results in a browser with the query builder UI at localhost:8080/querybuilder/. The query builder has guided queries and YQL autocompletion. Read more in the Query API.

  14. Run a document get request:
    $ curl -s http://localhost:8080/document/v1/mynamespace/music/docid/love-is-here-to-stay
    
  15. Clean up:

    Stop the running container:

    $ kubectl delete service,statefulsets vespa
    

    Stop port forwarding:

    $ killall kubectl
    

    Stop minikube:

    $ minikube stop