> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy with Kubernetes

## Deployment

<Note>
  Single-replica deployment still works as before. For multi-replica deployment, see [High Availability](/get-started/self-host/high-availability/).
</Note>

Here is a sample Kubernetes YAML file `bytebase.yaml` describing the minimal components and configuration required to run Bytebase in Kubernetes.

```yaml theme={null}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: bytebase
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bytebase
  template:
    metadata:
      labels:
        app: bytebase
    spec:
      containers:
        - name: bytebase
          image: bytebase/bytebase:latest
          imagePullPolicy: Always
          # Configure external PostgreSQL following the guide:
          # https://www.bytebase.com/docs/get-started/self-host/external-postgres
          env:
            - name: PG_URL
              value: 'postgresql://<<user>>:<<secret>>@<<host>>:<<port>>/<<dbname>>'
          args:
            [
              '--port',
              '8080',
            ]
          ports:
            - containerPort: 8080
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8080
            initialDelaySeconds: 300
            periodSeconds: 300
            timeoutSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: bytebase-entrypoint
  namespace: default
spec:
  # Optional
  type: ClusterIP
  selector:
    app: bytebase
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
```

1. Start Bytebase with the following command:

   ```bash theme={null}
   kubectl apply -f bytebase.yaml
   ```

2. Make sure everything worked by listing your deployments:

   ```bash theme={null}
   kubectl get statefulsets
   ```

   Do the same check for your services:

   ```bash theme={null}
   kubectl get services
   ```

## Deploy with Helm

Bytebase provides an official Helm chart for simplified Kubernetes deployments. For comprehensive configuration options and advanced settings, visit the [Bytebase Helm Chart on Artifact Hub](https://artifacthub.io/packages/helm/bytebase/bytebase).

<Note>
  The current official Helm chart deploys a single replica and does not yet expose HA-specific settings such as replica count and the `--ha` flag. If you want to run Bytebase in HA mode today, use a custom manifest based on this guide or customize the chart template before deploying.
</Note>

### Installation

Deploy Bytebase using Helm with your external PostgreSQL database:

```bash theme={null}
helm -n <YOUR_NAMESPACE> \
--set "bytebase.option.externalPg.url"={PGDSN} \
--set "bytebase.version"={VERSION} \
install <RELEASE_NAME> bytebase-repo/bytebase
```

To let the chart construct `PG_URL` from external PostgreSQL fields, set the host, port, username, database, and authentication-specific values instead of `bytebase.option.externalPg.url`.

For AWS RDS IAM authentication:

```bash theme={null}
helm -n <YOUR_NAMESPACE> \
--set "bytebase.option.externalPg.pgHost"={RDS_ENDPOINT} \
--set "bytebase.option.externalPg.pgPort"=5432 \
--set "bytebase.option.externalPg.pgUsername"={DB_USER} \
--set "bytebase.option.externalPg.pgDatabase"={DB_NAME} \
--set "bytebase.option.externalPg.awsRdsIam.enabled"=true \
--set "bytebase.option.externalPg.awsRdsIam.region"={AWS_REGION} \
--set "bytebase.version"={VERSION} \
install <RELEASE_NAME> bytebase-repo/bytebase
```

For GCP Cloud SQL IAM authentication:

```bash theme={null}
helm -n <YOUR_NAMESPACE> \
--set "bytebase.option.externalPg.pgUsername"={IAM_DATABASE_USER} \
--set "bytebase.option.externalPg.pgDatabase"={DB_NAME} \
--set "bytebase.option.externalPg.gcpCloudSqlIam.enabled"=true \
--set "bytebase.option.externalPg.gcpCloudSqlIam.instanceConnectionName"={PROJECT_ID:REGION:INSTANCE_ID} \
--set "bytebase.version"={VERSION} \
install <RELEASE_NAME> bytebase-repo/bytebase
```

See [Configure External PostgreSQL](/get-started/self-host/external-postgres/#iam-authentication-for-managed-postgresql) for the required AWS or GCP IAM setup.

### Uninstallation

To remove the Bytebase deployment:

```bash theme={null}
helm delete --namespace <YOUR_NAMESPACE> <RELEASE_NAME>
```

## HA Deployment

To run Bytebase with multiple replicas on Kubernetes:

1. Configure an external PostgreSQL database with `PG_URL`.
2. Set `replicas` to more than `1`.
3. Add the `--ha` flag to every Bytebase replica.
4. Put the replicas behind one stable ingress, gateway, or service entrypoint.
5. Make sure the workspace license has HA enabled.

Example:

```yaml theme={null}
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: bytebase
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: bytebase
  serviceName: bytebase
  template:
    metadata:
      labels:
        app: bytebase
    spec:
      containers:
        - name: bytebase
          image: bytebase/bytebase:latest
          env:
            - name: PG_URL
              value: 'postgresql://<<user>>:<<secret>>@<<host>>:<<port>>/<<dbname>>'
          args:
            - '--port'
            - '8080'
            - '--ha'
          ports:
            - containerPort: 8080
```
