Install Sourcegraph with minikube

This guide will take you through how to set up a Sourcegraph deployment locally with minikube, a tool that lets you run a single-node Kubernetes cluster on your local machine, using our minikube overlay.

Sourcegraph minikube overlay

The Sourcegraph minikube overlay deletes resource declarations and storage classnames to enable running Sourcegraph on minikube locally with less resources, as it normally takes a lot more of resources to run Sourcegraph at a production level. See our docs on creating kustomize overlays if you would like to customize the overlay.

Prerequisites

Following are the prerequisites for running Sourcegraph with minikube on your local machine.

Deploy

1\. Start a minikube cluster

# Docker must be running in the background
$ minikube start

2\. Apply manifests generated by the remote minikube overlay from deploy-sourcegraph-k8s

$ kubectl apply --prune -l deploy=sourcegraph -k https://github.com/sourcegraph/deploy-sourcegraph-k8s/examples/minikube

3\. Make sure all the pods are up and running before moving to the next step

$ kubectl get pods -n ns-sourcegraph
minikube-terminal-screen

4\. Create a Service object that exposes the deployment

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

5\. Start connnecting to the service endpoint for Sourcegraph

$ minikube service --url sourcegraph

# > Example IP address return http://127.0.0.1:32034

That's it! You can now access Sourcegraph in your browser using the IP address from the previous step. 🎉

minikube-startup-screen

Upgrade

Please refer to the upgrade docs for all Sourcegraph kubernetes instances.

Quick upgrade

Replace $NEW_VERSION with a new version number (must be v4.5.0+).

$ kubectl apply --prune -l deploy=sourcegraph -k https://github.com/sourcegraph/deploy-sourcegraph-k8s/examples/minikube/base?ref=$NEW_VERSION

For example, to upgrade from 4.5.0 to 4.5.1:

$ kubectl apply --prune -l deploy=sourcegraph -k https://github.com/sourcegraph/deploy-sourcegraph-k8s/examples/minikube/base?ref=v4.5.1

Downgrade

Same instruction as upgrades.

Uninstall

Steps to remove your Sourcegraph minikube instance:

1\. Stop the minikube node

$ minikube stop

2\. Remove the minikube cluster

$ minikube delete

Commands

Below is a list of userful commands when deploying Sourcegraph to minikube.

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

Get the service endpoint for Sourcegraph specifically

$ minikube service sourcegraph -n ns-sourcegraph

Get the service endpoint URL for Sourcegraph specificlly

$ minikube service --url sourcegraph -n ns-sourcegraph

# Example return: http://127.0.0.1:32034

Get a list of service endpoint

$ minikube service list

Example output:

|-------------|-------------------------------|--------------|-----|
|  NAMESPACE  |             NAME              | TARGET PORT  | URL |
|-------------|-------------------------------|--------------|-----|
| default     | blobstore                     | No node port |
| default     | codeinsights-db               | No node port |
| default     | codeintel-db                  | No node port |
| default     | github-proxy                  | No node port |
| default     | gitserver                     | No node port |
| default     | indexed-search                | No node port |
| default     | indexed-search-indexer        | No node port |
| default     | kubernetes                    | No node port |
| default     | pgsql                         | No node port |
| default     | precise-code-intel-worker     | No node port |
| default     | redis-cache                   | No node port |
| default     | redis-store                   | No node port |
| default     | repo-updater                  | No node port |
| default     | searcher                      | No node port |
| default     | sourcegraph                   |         3080 |     |
| default     | sourcegraph-frontend          | No node port |
| default     | sourcegraph-frontend-internal | No node port |
| default     | symbols                       | No node port |
| default     | syntect-server                | No node port |
| default     | worker                        | No node port |
| default     | worker-executors              | No node port |
| kube-system | kube-dns                      | No node port |
|-------------|-------------------------------|--------------|-----|

Resources