• [+] 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.

  1. Validate environment:

    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 --depth 1 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
            env:
            - name: VESPA_CONFIGSERVERS
              value: vespa-0.vespa.default.svc.cluster.local
            securityContext:
              privileged: true
              runAsUser: 0
            ports:
            - containerPort: 8080
              protocol: TCP
            readinessProbe:
              httpGet:
                path: /state/v1/health
                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/state/v1/health
    
  9. Zip the application package:
    $ (cd ${VESPA_SAMPLE_APPS}/album-recommendation && \
      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/state/v1/health
    
  12. Feed documents:
    $ curl -s -H "Content-Type:application/json" \
      --data-binary @${VESPA_SAMPLE_APPS}/album-recommendation/ext/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/ext/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/ext/Hardwired...To-Self-Destruct.json \
      http://localhost:8080/document/v1/mynamespace/music/docid/hardwired-to-self-destruct
    
  13. Make a query:

    $ curl -X POST -H "Content-Type: application/json" --data '
      {
        "yql": "select * from sources * where true",
        "input.query(user_profile)": "{{cat:pop}:0.8,{cat:rock}:0.2,{cat:jazz}:0.1}"
      }' \
      http://localhost:8080/search/
    

    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