Vespa quick start using Kubernetes

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

Prerequisites:

  • Minikube installed with xhyve driver.
  • Git installed.
  • Operating system: macOS
  • Architecture: x86_64
  • At least 4GB of memory dedicated to your container instance.

  1. Start Kubernetes cluster with minicube:
    $ minikube start --vm-driver xhyve --memory 4096
    
  2. Clone the Vespa sample apps from github:
    $ git clone https://github.com/vespa-engine/sample-apps.git
    $ export VESPA_SAMPLE_APPS=`pwd`/sample-apps
    
  3. Create Kubernetes configuration files:
    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
    
    statefulset.yml:
    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
      name: vespa
      labels:
        app: vespa
    spec:
      replicas: 1
      serviceName: 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
            volumeMounts:
            - name: vespa-sample-apps
              mountPath: /vespa-sample-apps
          volumes:
          - name: vespa-sample-apps
            hostPath:
              path: PATH_TO_CLONED/sample-apps
    
    Replace the PATH_TO_CLONED with the current path.
  4. Start the service:
    $ kubectl apply -f service.yml -f statefulset.yml
    
  5. Wait for the service to enter a running state:
    $ kubectl get pods --watch
    
  6. Deploy and activate a sample application:
    $ kubectl exec vespa-0 -- bash -c '/opt/vespa/bin/vespa-deploy prepare /vespa-sample-apps/album-recommendation-selfhosted/src/main/application/ && \
      /opt/vespa/bin/vespa-deploy activate'
    
  7. Start port forwarding from localhost to pod:
    $ kubectl port-forward vespa-0 8080 &
    
  8. Ensure the application is active - wait for a 200 OK response:
    $ curl -s --head http://localhost:8080/ApplicationStatus
    
  9. Feed documents:
    $ curl -s -H "Content-Type:application/json" --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation-selfhosted/src/test/resources/A-Head-Full-of-Dreams.json \
        http://localhost:8080/document/v1/mynamespace/music/docid/1
    $ curl -s -H "Content-Type:application/json" --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation-selfhosted/src/test/resources/Love-Is-Here-To-Stay.json \
        http://localhost:8080/document/v1/mynamespace/music/docid/2
    $ curl -s -H "Content-Type:application/json" --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation-selfhosted/src/test/resources/Hardwired...To-Self-Destruct.json \
        http://localhost:8080/document/v1/mynamespace/music/docid/3
    
  10. 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%3B&ranking.features.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 http://localhost:8080/querybuilder/. The query builder has guided queries and YQL autocompletion. Read more in the Query API.

  11. Run a document get request :
    $ curl -s http://localhost:8080/document/v1/mynamespace/music/docid/2
    
  12. Clean up:

    Stop the running container:

    $ kubectl delete service,statefulsets vespa
    

    Stop minikube:

    $ minikube stop