Deploy Sourcegraph on your own infrastructure using Docker Compose for smaller teams or Kubernetes with Helm for production-scale deployments.
Sourcegraph supports two primary self-hosted deployment methods. Choose based on your scale and operational capabilities.
Docker Compose
Kubernetes (Helm)
Best for
Small to medium teams
Large enterprises
Node count
Single node
Multi-node
Scaling
Vertical
Horizontal
Complexity
Lower
Higher
Recommended size
Up to ~M (5,000 users)
Any scale
Changing deployment methods after initial setup requires a full redeployment and database migration. Choose the right method for your long-term needs before going to production.
Docker Compose runs all Sourcegraph services as containers on a single host. It is easier to operate than Kubernetes and works well for teams up to a few thousand users.
The sourcegraph/deploy-sourcegraph-docker repository contains the docker-compose.yaml and all supporting configuration.Create a private copy of this repository in your own code host. Storing your customizations in version control makes upgrades much simpler — you track changes as a diff against the upstream repository.
# Bare clone the deployment repogit clone --bare https://github.com/sourcegraph/deploy-sourcegraph-docker/# Mirror push to your private repositorycd deploy-sourcegraph-docker.gitgit push --mirror https://github.com/your-org/sourcegraph-deploy.git# Clean up the bare clonecd ..rm -rf deploy-sourcegraph-docker.git
2
Create a release branch
Clone your private repository and create a release branch pinned to the version you want to install:
git clone https://github.com/your-org/sourcegraph-deploy.gitcd sourcegraph-deploy# Add the upstream repo so you can pull future releasesgit remote add upstream https://github.com/sourcegraph/deploy-sourcegraph-docker# Check out a release branch from the desired version tagexport SOURCEGRAPH_VERSION=6.5.0git checkout $SOURCEGRAPH_VERSION -b release
3
Customize the instance
Do not edit docker-compose.yaml directly. Instead, create a docker-compose.override.yaml file in the same directory. The override file is merged with the base config, so your changes survive upstream updates without merge conflicts.Common customizations in the override file:
Adjust CPU and memory limits for individual services
Add replicas for high-traffic services
Connect to an external PostgreSQL or Redis
Set environment variables
Mount custom TLS certificates
Commit the override file to your release branch.
4
Clone to the production server
On your production server, clone the release branch:
From the docker-compose directory, start all services:
cd docker-composedocker compose up -d
Check that the frontend is healthy:
docker ps --filter="name=sourcegraph-frontend-0"
Once the sourcegraph-frontend-0 container shows as healthy, navigate to your server’s IP or hostname on port 80. You will be prompted to create the initial site admin account.
6
Apply site configuration
After signing in as the initial admin, go to Site admin > Configuration to set your externalURL, connect code hosts, configure authentication, and add your license key. See Site configuration for details.
Sourcegraph’s Helm chart is the recommended deployment method for large enterprises. It supports multi-node clusters, horizontal scaling, and integrates with managed Kubernetes services on GKE, EKS, and AKS.
Ability to create DNS records for your Sourcegraph domain
Sourcegraph uses Server-Sent Events (SSE) for streaming search results. Your ingress controller or load balancer must allow connections to remain open for at least 5 minutes. Many ingress controllers default to shorter timeouts which will cause streaming to fail.
Create an override.yaml file for your customizations. Do not copy the full default values.yaml as a starting point — only include the values you need to change. This prevents stale values from causing issues during future upgrades.At minimum, configure your ingress hostname and storage class. Here is an example for a generic cluster:
When all pods show as Running, Sourcegraph is ready.
4
Configure DNS and TLS
Get the load balancer address:
kubectl describe ingress sourcegraph-frontend
Create a DNS A record (or CNAME) pointing sourcegraph.example.com to the load balancer address.Configure TLS using your preferred method: a cloud-managed certificate, cert-manager with Let’s Encrypt, or a manually created TLS Secret.
5
Apply site configuration
Navigate to your Sourcegraph URL and create the initial admin account. Then go to Site admin > Configuration to configure code hosts, auth providers, and your license key.
GKE requires a BackendConfig resource for health check configuration. See the GKE example override for the full file including the BackendConfig.Note: GKE Autopilot clusters are not supported.
# Update the Helm repohelm repo update sourcegraph# Upgrade to the new versionhelm upgrade --install \ --values ./override.yaml \ --version 6.6.0 \ sourcegraph sourcegraph/sourcegraph# Watch pods restartkubectl get pods --watch
You can only upgrade one minor version at a time with a standard upgrade. To jump multiple versions, use a multi-version upgrade (MVU) with the migrator tool.
Multi-version upgrade: Scale down database-accessing services, run the migrator to apply database migrations, then upgrade the Helm chart.
# Scale down serviceskubectl get -n sourcegraph deploy --no-headers | \ awk '{print $1}' | \ xargs -n 1 -I % kubectl -n sourcegraph scale deployment % --replicas=0# Run migratorhelm upgrade --install -n sourcegraph \ --set "migrator.args={upgrade,--from=6.0.0,--to=6.5.0}" \ sourcegraph-migrator sourcegraph/sourcegraph-migrator \ --version 6.5.0# Then run the standard upgradehelm upgrade --install -f override.yaml \ --version 6.5.0 \ sourcegraph sourcegraph/sourcegraph
Always check the changelog for migration notes before upgrading.