Run a Kubernetes instance locally

minikube is a tool that lets you run a single-node Kubernetes cluster on your local machine. This document will take you through how to set up a Sourcegraph Kubernetes instance locally using minikube.

Prerequisites

You must have the following installed on your machine

Steps:

  1. Start your cluster (Docker must be running in the background)
minikube start
  1. Create a clone of our Kubernetes deployment repository deploy-sourcegraph
git clone https://github.com/sourcegraph/deploy-sourcegraph.git
  1. Check out the branch of the version you would like to deploy
git checkout $VERSION-NUMBER
  1. Apply the minikube overlay by running the following command in the root directory of the deploy-sourcegraph repository
    1. This minikube overlay deletes resource declarations and storage classnames to enable running Sourcegraph on minikube
    2. This is to limit the resources to run Sourcegraph locally as it takes normally a lot of resources to run Sourcegraph
    3. Read our docs on creating custom overlays if you would like to customize the minikube overlay with other overlays, like the non-privileged overlay for example
./overlay-generate-cluster.sh minikube generated-cluster
  1. Create the ns-sourcegraph namespace
kubectl create namespace ns-sourcegraph
  1. Apply the generated manifests from the generated-cluster directory
kubectl -n ns-sourcegraph apply --prune -l deploy=sourcegraph -f generated-cluster --recursive
  1. Make sure all the pods have been created successfully, and are up and running before you move to the next step image

  2. Create a Service object that exposes the deployment

kubectl -n ns-sourcegraph expose deployment sourcegraph-frontend --type=NodePort --name sourcegraph --port=3080 --target-port=3080

image

  1. Display the service list
minikube service list
  1. Access the newly deployed instance in browser (for Mac users)
minikube service sourcegraph -n ns-sourcegraph
  1. If you are on Linux, an URL will then be displayed in the Service List if the instance has been deployed successfully
|----------------|-------------------------------|--------------|---------------------------|
|   NAMESPACE    |             NAME              | TARGET PORT  |            URL            |
|----------------|-------------------------------|--------------|---------------------------|
| default        | kubernetes                    | No node port |
| kube-system    | kube-dns                      | No node port |
| ns-sourcegraph | backend                       | No node port |
| ns-sourcegraph | codeinsights-db               | No node port |
| ns-sourcegraph | codeintel-db                  | No node port |
| ns-sourcegraph | github-proxy                  | No node port |
| ns-sourcegraph | gitserver                     | No node port |
| ns-sourcegraph | grafana                       | No node port |
| ns-sourcegraph | indexed-search                | No node port |
| ns-sourcegraph | indexed-search-indexer        | No node port |
| ns-sourcegraph | jaeger-collector              | No node port |
| ns-sourcegraph | jaeger-query                  | No node port |
| ns-sourcegraph | minio                         | No node port |
| ns-sourcegraph | pgsql                         | No node port |
| ns-sourcegraph | precise-code-intel-worker     | No node port |
| ns-sourcegraph | prometheus                    | No node port |
| ns-sourcegraph | query-runner                  | No node port |
| ns-sourcegraph | redis-cache                   | No node port |
| ns-sourcegraph | redis-store                   | No node port |
| ns-sourcegraph | repo-updater                  | No node port |
| ns-sourcegraph | searcher                      | No node port |
| ns-sourcegraph | sourcegraph                   |         3080 | http://127.0.0.1:32034 |
| ns-sourcegraph | sourcegraph-frontend          | No node port |
| ns-sourcegraph | sourcegraph-frontend-internal | No node port |
| ns-sourcegraph | symbols                       | No node port |
| ns-sourcegraph | syntect-server                | No node port |
| ns-sourcegraph | worker                        | No node port |
|----------------|-------------------------------|--------------|---------------------------|

image

Remove the instance

  1. Delete the ns-sourcegraph namespace
kubectl delete namespaces ns-sourcegraph
  1. Stop the minikube cluster
minikube stop

Other userful commands

Un-expose sourcegraph

kubectl delete service sourcegraph -n ns-sourcegraph

Gets a list of deployed services and cluster IP

kubectl get svc -n ns-sourcegraph

Deletes the minikube cluster

minikube delete

Resources